Skip to content

Commit

Permalink
Allow newer thecodingmachine/safe (#1649)
Browse files Browse the repository at this point in the history
* Use newer thecodingmachine/safe

* fix new thecodingmachine/safe PHPStan violations
  • Loading branch information
mmoll committed Feb 3, 2022
1 parent d5329d6 commit 4a1a2fd
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 37 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"symfony/filesystem": "^3.4.29 || ^4.1.19 || ^5.0 || ^6.0",
"symfony/finder": "^3.4.29 || ^4.1.19 || ^5.0 || ^6.0",
"symfony/process": "^3.4.29 || ^4.1.19 || ^5.0 || ^6.0",
"thecodingmachine/safe": "^1.1.3",
"thecodingmachine/safe": "^2.1.2",
"webmozart/assert": "^1.3",
"webmozart/path-util": "^2.3"
},
Expand All @@ -83,7 +83,7 @@
"phpunit/phpunit": "^9.3.11",
"symfony/phpunit-bridge": "^4.4.18 || ^5.1.10",
"symfony/yaml": "^5.0",
"thecodingmachine/phpstan-safe-rule": "^1.1.0"
"thecodingmachine/phpstan-safe-rule": "^1.2.0"
},
"config": {
"platform": {
Expand Down
47 changes: 23 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions devTools/phpstan-src.neon
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ parameters:
-
path: '../src/Logger/Html/StrykerHtmlReportBuilder.php'
message: '#return type with generic class ArrayObject does not specify its types\: TKey, TValue#'
-
message: '#^Function shell_exec is unsafe to use#'
path: '../src/TestFramework/CommandLineBuilder.php'

level: 8
paths:
- ../src
Expand Down
4 changes: 2 additions & 2 deletions src/Logger/GitHubAnnotationsLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
namespace Infection\Logger;

use Infection\Metrics\ResultsCollector;
use function shell_exec;
use function Safe\shell_exec;
use function str_replace;
use function trim;
use Webmozart\PathUtil\Path;
Expand All @@ -55,7 +55,7 @@ public function __construct(private ResultsCollector $resultsCollector)
public function getLogLines(): array
{
$lines = [];
$projectRootDirectory = trim((string) shell_exec('git rev-parse --show-toplevel'));
$projectRootDirectory = trim(shell_exec('git rev-parse --show-toplevel'));

foreach ($this->resultsCollector->getEscapedExecutionResults() as $escapedExecutionResult) {
$error = [
Expand Down
7 changes: 5 additions & 2 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
use function count;
use function explode;
use function implode;
use function mb_convert_encoding;
use const PHP_EOL;
use function Safe\mb_convert_encoding;
use function str_replace;
use function trim;

Expand Down Expand Up @@ -93,6 +93,9 @@ public static function trimLineReturns(string $string): string

public static function convertToUtf8(string $string): string
{
return mb_convert_encoding($string, 'UTF-8', 'UTF-8');
/** @var string $utf8String */
$utf8String = mb_convert_encoding($string, 'UTF-8', 'UTF-8');

return $utf8String;
}
}
11 changes: 9 additions & 2 deletions tests/phpunit/AutoReview/Makefile/MakefileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
use function implode;
use PHPUnit\Framework\TestCase;
use function Safe\array_replace;
use Safe\Exceptions\ExecException;
use function Safe\file_get_contents;
use function Safe\shell_exec;
use function Safe\sprintf;
use function Safe\substr;
use function shell_exec;
use function strpos;
use function substr_count;

Expand All @@ -62,9 +63,15 @@ final class MakefileTest extends TestCase

public function test_the_default_goal_is_the_help_command(): void
{
try {
shell_exec('command -v timeout');
$timeout = 'timeout 2s';
} catch (ExecException) {
$timeout = '';
}
$output = shell_exec(sprintf(
'%s make --silent --file %s 2>&1',
shell_exec('command -v timeout') !== null ? 'timeout 2s' : '',
$timeout,
self::MAKEFILE_PATH
));

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Config/ValueProvider/BaseProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

namespace Infection\Tests\Config\ValueProvider;

use function exec;
use PHPUnit\Framework\TestCase;
use function Safe\exec;
use function Safe\fopen;
use function Safe\fwrite;
use function Safe\rewind;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Configuration/Schema/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
use Infection\Configuration\Schema\SchemaConfigurationFile;
use Infection\Configuration\Schema\SchemaValidator;
use function Infection\Tests\normalizeLineReturn;
use function json_last_error_msg;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use function Safe\json_decode;
use function Safe\json_last_error_msg;
use Webmozart\Assert\Assert;

final class SchemaValidatorTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/FileSystem/SourceFileCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
use function array_values;
use function count;
use Infection\FileSystem\SourceFileCollector;
use function natcasesort;
use PHPUnit\Framework\TestCase;
use function Pipeline\take;
use function range;
use function Safe\natcasesort;
use Webmozart\PathUtil\Path;

final class SourceFileCollectorTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Mutator/BaseMutatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use function array_shift;
use function count;
use function escapeshellarg;
use function exec;
use Infection\Mutator\Mutator;
use Infection\PhpParser\NodeTraverserFactory;
use Infection\PhpParser\Visitor\CloneVisitor;
Expand All @@ -50,6 +49,7 @@
use Infection\Tests\StringNormalizer;
use PhpParser\NodeTraverser;
use PHPUnit\Framework\TestCase;
use function Safe\exec;
use function Safe\sprintf;
use Webmozart\Assert\Assert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use DOMNodeList;
use DOMXPath;
use function escapeshellarg;
use function exec;
use Infection\AbstractTestFramework\Coverage\TestLocation;
use Infection\StreamWrapper\IncludeInterceptor;
use Infection\TestFramework\Coverage\JUnit\JUnitTestCaseSorter;
Expand All @@ -51,6 +50,7 @@
use Infection\Tests\FileSystem\FileSystemTestCase;
use function Infection\Tests\normalizePath as p;
use function iterator_to_array;
use function Safe\exec;
use function Safe\file_get_contents;
use function Safe\realpath;
use function Safe\simplexml_load_string;
Expand Down

0 comments on commit 4a1a2fd

Please sign in to comment.