Browse Source

Merge pull request #9945 from ondrejmirtes/phpstan

Improving PHPStan configuration
ADmad 9 years ago
parent
commit
633c4b1ade

+ 1 - 1
.travis.yml

@@ -96,7 +96,7 @@ script:
 
   - if [[ $PHPCS = 1 ]]; then composer cs-check; fi
   - if [[ $PHPCS = 3 ]]; then vendor/bin/phpcs -p -s --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
-  - if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:dev-master && vendor/bin/phpstan analyse -c phpstan.neon -l 0 src; fi
+  - if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.5.1 && vendor/bin/phpstan analyse -c phpstan.neon -l 0 src; fi
 
 after_success:
   - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi

+ 1 - 0
composer.json

@@ -48,6 +48,7 @@
     },
     "autoload-dev": {
         "psr-4": {
+            "Cake\\PHPStan\\": "tests/PHPStan",
             "Cake\\Test\\": "tests",
             "TestApp\\": "tests/test_app/TestApp",
             "TestPlugin\\": "tests/test_app/Plugin/TestPlugin/src",

+ 18 - 0
phpstan.neon

@@ -1,3 +1,21 @@
 parameters:
 	autoload_files:
 		- %rootDir%/../../../src/basics.php
+	ignoreErrors:
+		- '#Function wincache_ucache_[a-zA-Z0-9_]+ not found#'
+		- '#Function xcache_[a-zA-Z0-9_]+ not found#'
+		- '#Function fastcgi_[a-zA-Z0-9_]+ not found#'
+		- '#Function apache_[a-zA-Z0-9_]+ not found#'
+		- '#Cake\\Database\\Type\\[a-zA-Z0-9_]+Type::__construct\(\) does not call parent constructor from Cake\\Database\\Type#'
+		- '#Constructor of class Cake\\[a-zA-Z0-9_\\]+ has an unused parameter#'
+		- '#Call to an undefined method Cake\\Console\\Shell::main\(\)#'
+		- '#Access to undefined constant Memcached::OPT_CLIENT_MODE#'
+		- '#Access to undefined constant Memcached::DYNAMIC_CLIENT_MODE#'
+		- '#Access to undefined constant PDO::SQLSRV_ENCODING_BINARY#'
+
+services:
+    -
+        class: Cake\PHPStan\AssociationTableMixinClassReflectionExtension
+        tags:
+            - phpstan.broker.methodsClassReflectionExtension
+            - phpstan.broker.propertiesClassReflectionExtension

+ 5 - 0
src/Cache/Engine/MemcachedEngine.php

@@ -89,6 +89,11 @@ class MemcachedEngine extends CacheEngine
     protected $_serializers = [];
 
     /**
+     * @var string[]
+     */
+    protected $_compiledGroupNames = [];
+
+    /**
      * Initialize the Cache Engine
      *
      * Called automatically by the cache frontend

+ 7 - 0
src/Database/Schema/SqliteSchema.php

@@ -31,6 +31,13 @@ class SqliteSchema extends BaseSchema
     protected $_constraintsIdMap = [];
 
     /**
+     * Whether there is any table in this connection to SQLite containing sequences.
+     *
+     * @var bool
+     */
+    protected $_hasSequences;
+
+    /**
      * Convert a column definition to the abstract types.
      *
      * The returned type will be a type that

+ 10 - 0
src/Datasource/QueryCacher.php

@@ -30,6 +30,16 @@ class QueryCacher
 {
 
     /**
+     * @var string|callable
+     */
+    protected $_key;
+
+    /**
+     * @var string|CacheEngine
+     */
+    protected $_config;
+
+    /**
      * Constructor.
      *
      * @param string|\Closure $key The key or function to generate a key.

+ 1 - 1
src/ORM/Association/Loader/SelectWithPivotLoader.php

@@ -171,7 +171,7 @@ class SelectWithPivotLoader extends SelectLoader
             if (!isset($result[$this->junctionProperty])) {
                 throw new RuntimeException(sprintf(
                     '"%s" is missing from the belongsToMany results. Results cannot be created.',
-                    $this->_junctionProperty
+                    $this->junctionProperty
                 ));
             }
 

+ 5 - 0
src/Shell/I18nShell.php

@@ -35,6 +35,11 @@ class I18nShell extends Shell
     public $tasks = ['Extract'];
 
     /**
+     * @var string[]
+     */
+    protected $_paths;
+
+    /**
      * Override main() for help message hook
      *
      * @return void

+ 4 - 0
src/Shell/PluginShell.php

@@ -19,6 +19,10 @@ use Cake\Core\Plugin;
 
 /**
  * Shell for tasks related to plugins.
+ *
+ * @property \Cake\Shell\Task\AssetsTask $Assets
+ * @property \Cake\Shell\Task\LoadTask $Load
+ * @property \Cake\Shell\Task\UnloadTask $Unload
  */
 class PluginShell extends Shell
 {

+ 6 - 0
src/TestSuite/LegacyRequestDispatcher.php

@@ -25,6 +25,12 @@ use Cake\TestSuite\Stub\Response;
  */
 class LegacyRequestDispatcher
 {
+
+    /**
+     * @var \Cake\TestSuite\IntegrationTestCase
+     */
+    protected $_test;
+
     /**
      * Constructor
      *

+ 86 - 0
tests/PHPStan/AssociationTableMixinClassReflectionExtension.php

@@ -0,0 +1,86 @@
+<?php declare(strict_types = 1);
+
+namespace Cake\PHPStan;
+
+use Cake\ORM\Association;
+use Cake\ORM\Table;
+use PHPStan\Broker\Broker;
+use PHPStan\Reflection\BrokerAwareClassReflectionExtension;
+use PHPStan\Reflection\ClassReflection;
+use PHPStan\Reflection\MethodReflection;
+use PHPStan\Reflection\MethodsClassReflectionExtension;
+use PHPStan\Reflection\PropertiesClassReflectionExtension;
+use PHPStan\Reflection\PropertyReflection;
+
+class AssociationTableMixinClassReflectionExtension implements PropertiesClassReflectionExtension, MethodsClassReflectionExtension, BrokerAwareClassReflectionExtension
+{
+    /**
+     * @var \PHPStan\Broker\Broker
+     */
+    private $broker;
+
+    /**
+     * @param Broker $broker Class reflection broker
+     * @return void
+     */
+    public function setBroker(Broker $broker)
+    {
+        $this->broker = $broker;
+    }
+
+    /**
+     * @return ClassReflection
+     */
+    protected function getTableReflection(): ClassReflection
+    {
+        return $this->broker->getClass(Table::class);
+    }
+
+    /**
+     * @param ClassReflection $classReflection Class reflection
+     * @param string $methodName Method name
+     * @return bool
+     */
+    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
+    {
+        if (!$classReflection->isSubclassOf(Association::class)) {
+            return false;
+        }
+
+        return $this->getTableReflection()->hasMethod($methodName);
+    }
+
+    /**
+     * @param ClassReflection $classReflection Class reflection
+     * @param string $methodName Method name
+     * @return MethodReflection
+     */
+    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
+    {
+        return $this->getTableReflection()->getMethod($methodName);
+    }
+
+    /**
+     * @param ClassReflection $classReflection Class reflection
+     * @param string $propertyName Method name
+     * @return bool
+     */
+    public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
+    {
+        if (!$classReflection->isSubclassOf(Association::class)) {
+            return false;
+        }
+
+        return $this->getTableReflection()->hasProperty($propertyName);
+    }
+
+    /**
+     * @param ClassReflection $classReflection Class reflection
+     * @param string $propertyName Method name
+     * @return PropertyReflection
+     */
+    public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
+    {
+        return $this->getTableReflection()->getProperty($propertyName);
+    }
+}