Skip to content

Commit

Permalink
Remove unnecessary code (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Dec 4, 2022
1 parent fcf6d38 commit 7454c93
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 12 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
EOF,
74_000,
);
$config->addRules(['mb_str_functions' => false]);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');

return $config->setFinder($finder);
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ COVERAGE_INFECTION = $(COVERAGE_XML) $(COVERAGE_JUNIT)
TARGET_MSI = 100

INFECTION_BIN = tools/infection
INFECTION = $(INFECTION_BIN) --skip-initial-tests --coverage=$(COVERAGE_DIR) --show-mutations --ansi
INFECTION = $(INFECTION_BIN) --skip-initial-tests --coverage=$(COVERAGE_DIR) --only-covered --show-mutations --ansi
INFECTION_WITH_INITIAL_TESTS = $(INFECTION_BIN) --only-covered --show-mutations --ansi

PHPUNIT_BIN = vendor/bin/phpunit
PHPUNIT = php -d zend.enable_gc=0 $(PHPUNIT_BIN)
Expand Down Expand Up @@ -132,7 +133,11 @@ phpunit_coverage_html: $(PHPUNIT_BIN) vendor

.PHONY: infection
infection: ## Runs infection
infection: $(INFECTION_BIN) $(COVERAGE_INFECTION) vendor
infection: $(INFECTION_BIN) vendor
$(INFECTION_WITH_INITIAL_TESTS)

.PHONY: _infection
_infection: $(INFECTION_BIN) $(COVERAGE_XML) $(COVERAGE_JUNIT) vendor
$(INFECTION)

.PHONY: security
Expand Down Expand Up @@ -160,9 +165,15 @@ vendor: composer.json
$(PHPUNIT_BIN): vendor
touch -c $@

$(COVERAGE_INFECTION): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(COVERAGE_XML): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(PHPUNIT_COVERAGE_INFECTION)
touch -c $@
touch -c $(COVERAGE_JUNIT)

$(COVERAGE_JUNIT): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(PHPUNIT_COVERAGE_INFECTION)
touch -c $@
touch -c $(COVERAGE_XML)

# PHP-CS-Fixer itself does not depend on the vendor but the config file yes
$(PHP_CS_FIXER_BIN): $(PHIVE_BIN) vendor
Expand Down
14 changes: 12 additions & 2 deletions infection.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "./vendor/infection/infection/resources/schema.json",
"$schema": "./tools/infection/resources/schema.json",
"ignoreMsiWithNoMutations": true,
"logs": {
"text": ".build/infection/infection-log.txt"
Expand All @@ -11,5 +11,15 @@
"src"
]
},
"timeout": 10
"timeout": 10,

"mutators": {
"@default": true,
"ArrayItemRemoval": {
"ignore": [
"Fidry\\CpuCounter\\CpuCoreCounter::getDefaultFinders"
]
},
"PublicVisibility": false
}
}
4 changes: 2 additions & 2 deletions src/CpuInfoFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use function file_get_contents;
use function is_file;
use function mb_substr_count;
use function substr_count;

/**
* Find the number of CPU cores looking up at the cpuinfo file which is available
Expand Down Expand Up @@ -58,7 +58,7 @@ private static function getCpuInfo(): ?string
*/
public static function countCpuCores(string $cpuInfo): ?int
{
$processorCount = mb_substr_count($cpuInfo, 'processor');
$processorCount = substr_count($cpuInfo, 'processor');

return $processorCount > 0 ? $processorCount : null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/HwFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use function is_resource;
use function pclose;
use function popen;
use function trim;
use const FILTER_VALIDATE_INT;

/**
Expand Down Expand Up @@ -63,7 +62,7 @@ public function find(): ?int
*/
public static function countCpuCores(string $process): ?int
{
$cpuCount = filter_var(trim($process), FILTER_VALIDATE_INT);
$cpuCount = filter_var($process, FILTER_VALIDATE_INT);

return is_int($cpuCount) && $cpuCount > 0 ? $cpuCount : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NProcFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static function supportsNproc(): bool
*/
public static function countCpuCores(string $nproc): ?int
{
$cpuCount = filter_var(trim($nproc), FILTER_VALIDATE_INT);
$cpuCount = filter_var($nproc, FILTER_VALIDATE_INT);

return is_int($cpuCount) && $cpuCount > 0 ? $cpuCount : null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/WindowsWmicFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use function is_resource;
use function pclose;
use function popen;
use function trim;
use const FILTER_VALIDATE_INT;

/**
Expand Down Expand Up @@ -64,7 +63,7 @@ public function find(): ?int
*/
public static function countCpuCores(string $process): ?int
{
$cpuCount = filter_var(trim($process), FILTER_VALIDATE_INT);
$cpuCount = filter_var($process, FILTER_VALIDATE_INT);

return is_int($cpuCount) && $cpuCount > 0 ? $cpuCount : null;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/CpuInfoFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static function cpuInfoProvider(): iterable
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF,
null,
];

// $ docker run --tty --rm --platform linux/amd64 alpine:3.14 cat /proc/cpuinfo
yield 'example from an alpine Docker image' => [
<<<'EOF'
Expand Down
14 changes: 14 additions & 0 deletions tests/HwFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static function processProvider(): iterable
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF,
null,
];

// MyMachine™
yield 'example from an OSX machine' => [
<<<'EOF'
Expand All @@ -52,6 +59,13 @@ public static function processProvider(): iterable
EOF,
3,
];
yield 'example with extra spaces' => [
<<<'EOF'
3

EOF,
3,
];

yield 'no processor' => [
<<<'EOF'
Expand Down
14 changes: 14 additions & 0 deletions tests/NProcFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static function nprocProvider(): iterable
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF,
null,
];

// $ docker run --tty --rm --platform linux/amd64 alpine:3.14 nproc --all
yield 'example from an alpine Docker image' => [
<<<'EOF'
Expand All @@ -52,6 +59,13 @@ public static function nprocProvider(): iterable
EOF,
3,
];
yield 'example with extra spaces' => [
<<<'EOF'
3

EOF,
3,
];

yield 'no processor' => [
<<<'EOF'
Expand Down
15 changes: 15 additions & 0 deletions tests/WindowsWmicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static function wmicProvider(): iterable
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF,
null,
];

yield 'example from a Windows machine' => [
<<<'EOF'
3
Expand All @@ -52,6 +59,14 @@ public static function wmicProvider(): iterable
3,
];

yield 'example from a Windows machine with extra spaces' => [
<<<'EOF'
3

EOF,
3,
];

yield 'no processor' => [
<<<'EOF'
0
Expand Down

0 comments on commit 7454c93

Please sign in to comment.