mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 18:11:52 -04:00
Add Safe PHP functions
This commit is contained in:
parent
04a956886a
commit
58cc098058
260 changed files with 49458 additions and 45 deletions
42
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/CallMethodRuleTest.php
vendored
Normal file
42
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/CallMethodRuleTest.php
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace TheCodingMachine\Safe\PHPStan\Rules;
|
||||
|
||||
use PHPStan\Rules\FunctionCallParametersCheck;
|
||||
use PHPStan\Rules\Methods\CallMethodsRule;
|
||||
use PHPStan\Rules\Rule;
|
||||
use PHPStan\Rules\RuleLevelHelper;
|
||||
use PHPStan\Testing\RuleTestCase;
|
||||
use TheCodingMachine\Safe\PHPStan\Type\Php\ReplaceSafeFunctionsDynamicReturnTypeExtension;
|
||||
|
||||
class CallMethodRuleTest extends RuleTestCase
|
||||
{
|
||||
protected function getRule(): Rule
|
||||
{
|
||||
$broker = $this->createBroker();
|
||||
$ruleLevelHelper = new RuleLevelHelper($broker, true, true, true);
|
||||
return new CallMethodsRule(
|
||||
$broker,
|
||||
new FunctionCallParametersCheck($ruleLevelHelper, true, true),
|
||||
$ruleLevelHelper,
|
||||
true,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function testSafePregReplace()
|
||||
{
|
||||
// FIXME: this rule actually runs code but will always return no error because the rule executed is not the correct one.
|
||||
// This provides code coverage but assert is not ok.
|
||||
$this->analyse([__DIR__ . '/data/safe_pregreplace.php'], []);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \PHPStan\Type\DynamicFunctionReturnTypeExtension[]
|
||||
*/
|
||||
public function getDynamicFunctionReturnTypeExtensions(): array
|
||||
{
|
||||
return [new ReplaceSafeFunctionsDynamicReturnTypeExtension()];
|
||||
}
|
||||
}
|
34
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/UseSafeFunctionsRuleTest.php
vendored
Normal file
34
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/UseSafeFunctionsRuleTest.php
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace TheCodingMachine\Safe\PHPStan\Rules;
|
||||
|
||||
use PHPStan\Testing\RuleTestCase;
|
||||
use TheCodingMachine\Safe\PHPStan\Type\Php\ReplaceSafeFunctionsDynamicReturnTypeExtension;
|
||||
|
||||
class UseSafeFunctionsRuleTest extends RuleTestCase
|
||||
{
|
||||
protected function getRule(): \PHPStan\Rules\Rule
|
||||
{
|
||||
return new UseSafeFunctionsRule();
|
||||
}
|
||||
|
||||
public function testCatch()
|
||||
{
|
||||
$this->analyse([__DIR__ . '/data/fopen.php'], [
|
||||
[
|
||||
"Function fopen is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\fopen;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.",
|
||||
4,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testNoCatchSafe()
|
||||
{
|
||||
$this->analyse([__DIR__ . '/data/safe_fopen.php'], []);
|
||||
}
|
||||
|
||||
public function testExprCall()
|
||||
{
|
||||
$this->analyse([__DIR__ . '/data/undirect_call.php'], []);
|
||||
}
|
||||
}
|
5
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/fopen.php
vendored
Normal file
5
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/fopen.php
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
function foo() {
|
||||
$fp = fopen('foobar', 'r');
|
||||
}
|
6
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/safe_fopen.php
vendored
Normal file
6
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/safe_fopen.php
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
use function Safe\fopen;
|
||||
|
||||
function foo() {
|
||||
$fp = fopen('foobar', 'r');
|
||||
}
|
7
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/safe_pregreplace.php
vendored
Normal file
7
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/safe_pregreplace.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
use function Safe\preg_replace;
|
||||
|
||||
$x = preg_replace('/foo/', 'bar', 'baz');
|
||||
$y = stripos($x, 'foo');
|
||||
|
||||
$x = preg_replace(['/foo/'], ['bar'], ['baz']);
|
5
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/undirect_call.php
vendored
Normal file
5
vendor/thecodingmachine/phpstan-safe-rule/tests/Rules/data/undirect_call.php
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
function foo() {
|
||||
$toto = 'fopen';
|
||||
$toto('foobar', 'r');
|
||||
}
|
15
vendor/thecodingmachine/phpstan-safe-rule/tests/Utils/FunctionListLoaderTest.php
vendored
Normal file
15
vendor/thecodingmachine/phpstan-safe-rule/tests/Utils/FunctionListLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace TheCodingMachine\Safe\PHPStan\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FunctionListLoaderTest extends TestCase
|
||||
{
|
||||
|
||||
public function testGetFunctionList()
|
||||
{
|
||||
$functions = FunctionListLoader::getFunctionList();
|
||||
$this->assertArrayHasKey('fopen', $functions);
|
||||
}
|
||||
}
|
33
vendor/thecodingmachine/phpstan-safe-rule/tests/bootstrap.php
vendored
Normal file
33
vendor/thecodingmachine/phpstan-safe-rule/tests/bootstrap.php
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Nette\Configurator;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
/*require_once __DIR__ . '/TestCase.php';
|
||||
require_once __DIR__ . '/PHPStan/Rules/AbstractRuleTest.php';
|
||||
require_once __DIR__ . '/PHPStan/Rules/AlwaysFailRule.php';
|
||||
require_once __DIR__ . '/PHPStan/Rules/DummyRule.php';*/
|
||||
|
||||
/*
|
||||
$rootDir = __DIR__ . '/..';
|
||||
$tmpDir = $rootDir . '/tmp';
|
||||
$confDir = $rootDir . '/vendor/phpstan/phpstan/conf';
|
||||
|
||||
$configurator = new Configurator();
|
||||
$configurator->defaultExtensions = [];
|
||||
$configurator->setDebugMode(true);
|
||||
$configurator->setTempDirectory($tmpDir);
|
||||
$configurator->addConfig($confDir . '/config.neon');
|
||||
$configurator->addConfig($confDir . '/config.level5.neon');
|
||||
$configurator->addParameters([
|
||||
'rootDir' => $rootDir,
|
||||
'tmpDir' => $tmpDir,
|
||||
'currentWorkingDirectory' => $rootDir,
|
||||
'cliArgumentsVariablesRegistered' => false,
|
||||
]);
|
||||
$container = $configurator->createContainer();
|
||||
|
||||
PHPStan\Testing\TestCase::setContainer($container);
|
||||
PHPStan\Type\TypeCombinator::setUnionTypesEnabled(true);
|
||||
require_once __DIR__ . '/phpstan-bootstrap.php';
|
||||
*/
|
4
vendor/thecodingmachine/phpstan-safe-rule/tests/phpstan-bootstrap.php
vendored
Normal file
4
vendor/thecodingmachine/phpstan-safe-rule/tests/phpstan-bootstrap.php
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
class_alias(\ReturnTypes\Foo::class, \ReturnTypes\FooAlias::class, true);
|
||||
class_alias(\TestAccessProperties\FooAccessProperties::class, \TestAccessProperties\FooAccessPropertiesAlias::class, true);
|
Loading…
Add table
Add a link
Reference in a new issue