first commit

This commit is contained in:
Valentin
2024-03-26 13:31:26 +01:00
commit a56b4dc2fc
922 changed files with 133572 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace PHPStan\Toolbox;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
/**
* Extension to handle UniformResourceLocator return types.
*/
class UniformResourceLocatorExtension implements DynamicMethodReturnTypeExtension
{
/**
* @return string
*/
public function getClass(): string
{
return UniformResourceLocator::class;
}
/**
* @param MethodReflection $methodReflection
* @return bool
*/
public function isMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === 'findResource';
}
/**
* @param MethodReflection $methodReflection
* @param MethodCall $methodCall
* @param Scope $scope
* @return Type
*/
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
$first = $methodCall->getArgs()[2] ?? false;
if ($first) {
return new StringType();
}
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
}
}

View File

@@ -0,0 +1,5 @@
services:
-
class: PHPStan\Toolbox\UniformResourceLocatorExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

View File

@@ -0,0 +1,7 @@
<?php declare(strict_types=1);
/**
*To help phpstan dealing with LogicException in Common\User\User.php
*/
define('GRAV_USER_INSTANCE', 'FLEX');
define('GRAV_REQUEST_TIME', microtime(true));

175
tests/phpstan/phpstan.neon Normal file
View File

@@ -0,0 +1,175 @@
#phpVersion: 70300
includes:
#- '../../vendor/phpstan/phpstan-strict-rules/rules.neon'
- '../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'
- 'extension.neon'
parameters:
fileExtensions:
- php
- dist
bootstrapFiles:
- phpstan-bootstrap.php
excludePaths:
- */system/src/Grav/Common/Errors/Resources/layout.html.php
- */system/src/Twig/DeferredExtension/DeferredNodeVisitorCompat.php # Twig 1
- */system/src/Twig/DeferredExtension/DeferredNodeVisitor.php # Twig 2+3
# Ignore vendor dev dependencies and tests
- */vendor/*/*/tests
- */vendor/behat
- */vendor/codeception
- */vendor/phpstan
- */vendor/phpunit
- */vendor/phpspec
- */vendor/phpdocumentor
- */vendor/sebastian
- */vendor/theseer
- */vendor/webmozart
inferPrivatePropertyTypeFromConstructor: true
reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false
# These checks are new in phpstan 1, ignore them for now.
checkMissingIterableValueType: false
#checkGenericClassInNonGenericObjectType: false
universalObjectCratesClasses:
- Grav\Common\Config\Config
- Grav\Common\Config\Languages
- Grav\Common\Config\Setup
- Grav\Common\Data\Data
- Grav\Common\GPM\Common\Package
- Grav\Common\GPM\Local\Package
- Grav\Common\GPM\Remote\Package
- Grav\Common\Page\Header
- Grav\Common\Session
dynamicConstantNames:
- GRAV_CLI
ignoreErrors:
# New in phpstan 1, ignore them for now.
- '#Unsafe usage of new static\(\)#'
# TODO: Errors that needs some more thinking (bad design?)
- '#Access to an undefined property RocketTheme\\Toolbox\\Event\\Event::#'
- '#Instantiation of deprecated class RocketTheme\\Toolbox\\Event\\Event#'
- '#extends deprecated class RocketTheme\\Toolbox\\Event\\Event#'
- '#Access to an undefined property Grav\\Common\\Data\\Blueprint::#'
-
message: '#Cannot call method path\(\) on string#'
path: '*/system/src/Grav/Common/Page/Media.php'
# TODO: system.twig.umask_fix will not work with Twig 2 anymore
-
message: '#Call to deprecated method writeCacheFile\(\) of class Twig\\Environment#'
path: '*/system/src/Grav/Common/Twig/WriteCacheFileTrait.php'
# PSR-16 Exception interfaces do not extend \Throwable
- '#PHPDoc tag \@throws with type Psr\\SimpleCache\\(CacheException|InvalidArgumentException) is not subtype of Throwable#'
# Medium __call() methods
- '#Call to an undefined method Grav\\Common\\Page\\Medium\\(\w*)Medium::#'
# These errors are about plugins (need to find a better solution)
-
message: '#Call to static method sendEmail\(\) on an unknown class Grav\\Plugin\\Email\\Utils#'
path: '*/system/src/Grav/Common/Scheduler/Job.php'
-
message: '#unknown class Grav\\Plugin\\Admin#'
path: '*/system/src/Grav/Common/Page/Pages.php'
-
message: '#unknown class Grav\\Plugin\\Admin#'
path: '*/system/src/Grav/Common/Flex/Pages/PageObject.php'
-
message: '#unknown class Grav\\Plugin\\Admin\\Admin#'
path: '*/system/src/Grav/Common/Flex/Types/Pages/PageObject.php'
-
message: '#unknown class Grav\\Plugin\\Form\\Forms#'
path: '*/system/src/Grav/Common/Processors/PagesProcessor.php'
# Clockwork does not define functions for __call() call
-
message: '#Call to an undefined method Clockwork\\Clockwork::(info|userData|addEvent|alert)\(\)#'
path: '*/system/src/Grav/Common/Debugger.php'
# These errors can be ignored (they depend on installed extensions)
-
message: '#Instantiated class (Memcache|Memcached|Redis|RedisException) not found#'
path: '*/system/src/Grav/Common/Cache.php'
-
message: '#unknown class (Memcache|Memcached|Redis|RedisException)#'
path: '*/system/src/Grav/Common/Cache.php'
-
message: '#unknown class Collator#'
path: '*/system/src/Grav/Common/Page/Pages.php'
-
message: '#unknown class Collator#'
path: '*/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php'
-
message: '#Ternary operator condition is always true#'
path: '*/system/src/Grav/Framework/Cache/AbstractCache.php'
-
message: '#Call to function is_object\(\) with int will always evaluate to false#'
path: '*/system/src/Grav/Framework/Cache/AbstractCache.php'
# XHprof
- '#tideways_xhprof_enable#'
# Support for deprecated features
-
message: '#Instantiation of deprecated class Doctrine\\Common\\Cache\\(\w+)Cache#'
path: '*/system/src/Grav/Common/Cache.php'
-
message: '#Instantiation of deprecated class Doctrine\\Common\\Cache\\(\w+)Cache#'
path: '*/system/src/Grav/Common/GPM/Remote/*.php'
-
message: '#Call to deprecated method order#'
path: '*/system/src/Grav/Common/Page/Pages.php'
-
message: '#Fetching class constant class of deprecated class Grav\\Common\\User\\User#'
path: '*/system/src/Grav/Common/Service/AccountsServiceProvider.php'
-
message: '#Call to deprecated method getLegacyFiles\(\)#'
path: '*/system/src/Grav/Common/Session.php'
-
message: '#Call to deprecated method \w+\(\) of class Grav\\Common\\Flex\\Types\\Users\\UserObject#'
path: '*/system/src/Grav/Common/Flex/Types/Users/UserObject.php'
-
message: '#Call to deprecated method \w+\(\) of class Grav\\Framework\\Flex\\FlexObject#'
path: '*/system/src/Grav/Framework/Flex/FlexObject.php'
-
message: '#Call to deprecated method \w+\(\) of class Grav\\Framework\\Flex\\FlexIndex#'
path: '*/system/src/Grav/Framework/Flex/FlexIndex.php'
-
message: '#Call to deprecated method \w+\(\) of class Grav\\Framework\\Flex\\FlexCollection#'
path: '*/system/src/Grav/Framework/Flex/FlexCollection.php'
-
message: '#Call to deprecated method (getAuthorizeScope|getActiveUser)\(\) of class Grav\\Framework\\Flex\\FlexObject#'
path: '*/system/src/Grav/Framework/Flex/Pages/Traits/PageAuthorsTrait.php'
-
message: '#deprecated class#'
path: '*/system/src/Grav/Framework/Uri/Uri.php'
-
message: '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch#'
path: '*/system/src/Grav/Common/Grav.php'
- '#has typehint with deprecated class RocketTheme\\Toolbox\\Event\\Event#'
- '#Call to deprecated method stopPropagation\(\) of class Symfony\\Component\\EventDispatcher\\Event#'
- '#Parameter \#2 \$listener of method Symfony\\Component\\EventDispatcher\\EventDispatcher::addListener\(\)#'
- '#Parameter \#2 \$listener of method Symfony\\Component\\EventDispatcher\\EventDispatcher::removeListener\(\)#'
- '#Class Grav\\Common\\GPM\\Response not found#'
# Installer updates
-
message: '#Variable \$this in PHPDoc tag @var does not exist#'
path: '*/system/src/Grav/Installer/updates/*'
-
message: '#YamlUpdater::isInlineComment\(\) is unused#'
path: '*/system/src/Grav/Installer/YamlUpdater.php'
# Twig Deferred extension compatibility
-
message: '#typehint with deprecated interface#'
path: '*/system/src/Twig/DeferredExtension/DeferredNodeVisitorCompat.php'
-
message: '#Function twig_array_filter not found#'
path: '*/system/src/Grav/Common/Twig/Extension/GravExtension.php'

View File

@@ -0,0 +1,64 @@
<?php
use Grav\Common\Grav;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
\define('GRAV_USER_INSTANCE', 'FLEX');
$autoload = require __DIR__ . '/../../vendor/autoload.php';
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
if (!file_exists(GRAV_ROOT . '/index.php')) {
exit('FATAL: Must be run from ROOT directory of Grav!');
}
$grav = Grav::instance(['loader' => $autoload]);
$grav->setup('tests');
$grav['config']->init();
// Find all plugins in Grav installation and autoload their classes.
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
$iterator = $locator->getIterator('plugins://');
/** @var DirectoryIterator $directory */
foreach ($iterator as $directory) {
if (!$directory->isDir()) {
continue;
}
$plugin = $directory->getBasename();
$file = $directory->getPathname() . '/' . $plugin . '.php';
$classloader = null;
if (file_exists($file)) {
require_once $file;
$pluginClass = "\\Grav\\Plugin\\{$plugin}Plugin";
if (is_subclass_of($pluginClass, Plugin::class, true)) {
$class = new $pluginClass($plugin, $grav);
if (is_callable([$class, 'autoload'])) {
$classloader = $class->autoload();
}
}
}
if (null === $classloader) {
$autoloader = $directory->getPathname() . '/vendor/autoload.php';
if (file_exists($autoloader)) {
require $autoloader;
}
}
}
define('GANTRY_DEBUGGER', true);
define('GANTRY5_DEBUG', true);
define('GANTRY5_PLATFORM', 'grav');
define('GANTRY5_ROOT', GRAV_ROOT);
define('GANTRY5_VERSION', '@version@');
define('GANTRY5_VERSION_DATE', '@versiondate@');
define('GANTRYADMIN_PATH', '');

View File

@@ -0,0 +1,70 @@
includes:
#- '../../vendor/phpstan/phpstan-strict-rules/rules.neon'
- '../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'
- 'extension.neon'
parameters:
fileExtensions:
- php
excludePaths:
- %currentWorkingDirectory%/user/plugins/*/vendor/*
- %currentWorkingDirectory%/user/plugins/*/tests/*
- %currentWorkingDirectory%/user/plugins/gantry5/src/platforms
- %currentWorkingDirectory%/user/plugins/gantry5/src/classes/Gantry/Framework/Services/ErrorServiceProvider.php
# Ignore vendor dev dependencies and tests
- */vendor/*/*/tests
- */vendor/behat
- */vendor/codeception
- */vendor/phpstan
- */vendor/phpunit
- */vendor/phpspec
- */vendor/phpdocumentor
- */vendor/sebastian
- */vendor/theseer
- */vendor/webmozart
bootstrapFiles:
- plugins-bootstrap.php
inferPrivatePropertyTypeFromConstructor: true
reportUnmatchedIgnoredErrors: false
# These checks are new in phpstan 1, ignore them for now.
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
universalObjectCratesClasses:
- Grav\Common\Config\Config
- Grav\Common\Config\Languages
- Grav\Common\Config\Setup
- Grav\Common\Data\Data
- Grav\Common\GPM\Common\Package
- Grav\Common\GPM\Local\Package
- Grav\Common\GPM\Remote\Package
- Grav\Common\Page\Header
- Grav\Common\Session
- Gantry\Component\Config\Config
dynamicConstantNames:
- GRAV_CLI
- GANTRY_DEBUGGER
- GANTRY5_DEBUG
- GANTRY5_VERSION
- GANTRY5_VERSION_DATE
- GANTRY5_PLATFORM
- GANTRY5_ROOT
ignoreErrors:
# New in phpstan 1, ignore them for now.
- '#Unsafe usage of new static\(\)#'
- '#Cannot instantiate interface Grav\\Framework\\#'
# PSR-16 Exception interfaces do not extend \Throwable
- '#PHPDoc tag \@throws with type (.*|)?Psr\\SimpleCache\\(CacheException|InvalidArgumentException)(|.*)? is not subtype of Throwable#'
- '#Access to an undefined property RocketTheme\\Toolbox\\Event\\Event::#'
- '#Instantiation of deprecated class RocketTheme\\Toolbox\\Event\\Event#'
- '#extends deprecated class RocketTheme\\Toolbox\\Event\\Event#'
- '#implements deprecated interface RocketTheme\\Toolbox\\Event\\EventSubscriberInterface#'
- '#Call to method __construct\(\) of deprecated class RocketTheme\\Toolbox\\Event\\Event#'
- '#Call to deprecated method (stopPropagation|isPropagationStopped)\(\) of class Symfony\\Component\\EventDispatcher\\Event#'
- '#Call to an undefined method Grav\\Plugin\\ApartmentData\\Application\\Application::#'
- '#Parameter \#1 \$lineNumberStyle of method ScssPhp\\ScssPhp\\Compiler::setLineNumberStyle\(\) expects string, int given#'
# Deprecated event class
- '#has typehint with deprecated class RocketTheme\\Toolbox\\Event\\Event#'