Skip to content

Commit

Permalink
Merge pull request #21 from sminnee/phpstan011
Browse files Browse the repository at this point in the history
NEW: Move to phpstan 0.11.
  • Loading branch information
Nathan authored Nov 11, 2019
2 parents 8fb6491 + ec0c81e commit 1ab1ca5
Show file tree
Hide file tree
Showing 27 changed files with 437 additions and 179 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/vendor/
/resources/
/assets/
/app/
.DS_Store
.phpunit.result.cache
composer.lock
27 changes: 9 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
language: php
php:
- 7.1
- 7.2
- 7.3

env:
global:
- COMPOSER_ROOT_VERSION=5.0.x-dev
- SS_BASE_URL="https://localhost/"
- DB=MYSQL
matrix:
- RECIPE_VERSION=4.3.x-dev
- RECIPE_VERSION=4.4.x-dev


matrix:
include:
# NOTE(Jake): 2018-05-16
#
# Running in PHP 7.0 doesn't seem to work.
#
# - php: 7.0
# env:
# - DB=MYSQL
# - RECIPE_VERSION=1.0.x-dev
- php: 7.1
env:
- DB=MYSQL
- RECIPE_VERSION=1.1.x-dev
- php: 7.2
env:
- DB=MYSQL
- RECIPE_VERSION=1.2.x-dev

before_script:
- phpenv rehash
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ composer require --dev symbiote/silverstripe-phpstan:1.0.0 phpstan/phpstan-shim:

SilverStripe 4.X
```
composer require --dev symbiote/silverstripe-phpstan:2.0.0 phpstan/phpstan-shim:0.9.2
composer require --dev symbiote/silverstripe-phpstan:2.0.0 phpstan/phpstan-shim:~0.11.0
```

NOTE: We recommend installing the phpstan-shim as currently in SilverStripe 3.X, the QueuedJobs module's dependence on superclosure forces the PHP-Parser dependency of PHPStan to be at a very outdated version.
Expand Down
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Jake Bentvelzen",
"email": "[email protected]"
}],
{
"name": "Jake Bentvelzen",
"email": "[email protected]"
}
],
"require": {
"php": "~7.0",
"silverstripe/framework": "~4.0",
"php": "~7.1",
"silverstripe/framework": "~4.3",
"silverstripe/vendor-plugin": "^1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"phpstan/phpstan": "~0.9.0",
"phpstan/phpstan-phpunit": "~0.9.0"
"phpstan/phpstan": "~0.11.0",
"phpstan/phpstan-phpunit": "~0.11.0",
"phpunit/phpunit": "^7.5.14 || ^8.0"
},
"scripts": {
"phpcs": "phpcs -n -l src/ src/Reflection/ src/Rule/ src/Type tests/ tests/Reflection/ tests/Rule/ tests/Type/",
Expand All @@ -33,7 +35,7 @@
"phpstan": "bash ../../../vendor/bin/phpstan analyse src/ tests/ -c \"tests/phpstan.neon\" -a \"tests/bootstrap-phpstan.php\" --level 4"
},
"suggest": {
"phpstan/phpstan-shim": "~0.9.0"
"phpstan/phpstan-shim": "~0.11.0"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ parameters:
universalObjectCratesClasses:
- SilverStripe\View\ArrayData
- SilverStripe\Core\Config\Config_ForClass
- SilverStripe\Forms\GridField\GridState_Data
- SilverStripe\ORM\DataObject
- SilverStripe\ORM\DataObjectInterface
- Symbiote\QueuedJobs\Services\AbstractQueuedJob # symbiote/silverstripe-queuedjobs module support
excludes_analyse:
- silverstripe-cache
Expand Down Expand Up @@ -65,9 +68,21 @@ services:
class: Symbiote\SilverstripePHPStan\Type\DataObjectReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

-
class: Symbiote\SilverstripePHPStan\Type\FormFieldReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

# This makes calls to `DBField::create_field('HTMLText', $value)` return the correct type info
# ie. The injectored type of the first parameter
-
class: Symbiote\SilverstripePHPStan\Type\DBFieldStaticReturnTypeExtension
tags:
- phpstan.broker.dynamicStaticMethodReturnTypeExtension

# Special handling for ->hasMethod() checks
-
class: Symbiote\SilverstripePHPStan\Type\HasMethodTypeSpecifyingExtension
tags:
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
2 changes: 1 addition & 1 deletion src/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function get($className, $configKey)
* @param string $className
* @param string $configKey
* @param string $configValue
* @return array|scalar
* @return \SilverStripe\Config\Collections\MutableConfigCollectionInterface
*/
public static function update($className, $configKey, $configValue)
{
Expand Down
31 changes: 20 additions & 11 deletions src/Reflection/CachedMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Type\Type;
use PHPStan\Type\MixedType;
use PHPStan\Reflection\Php\PhpMethodReflection;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function getDeclaringClass(): ClassReflection
return $this->methodReflection->getDeclaringClass();
}

public function getPrototype(): MethodReflection
public function getPrototype(): ClassMemberReflection
{
return $this->methodReflection->getPrototype();
}
Expand All @@ -53,15 +54,15 @@ public function isStatic(): bool
return $this->methodReflection->isStatic();
}

public function getParameters(): array
{
return $this->methodReflection->getParameters();
}
// public function getParameters(): array
// {
// return $this->methodReflection->getParameters();
// }

public function isVariadic(): bool
{
return $this->methodReflection->isVariadic();
}
// public function isVariadic(): bool
// {
// return $this->methodReflection->isVariadic();
// }

public function isPrivate(): bool
{
Expand All @@ -78,8 +79,16 @@ public function getName(): string
return $this->name;
}

public function getReturnType(): Type
// public function getReturnType(): Type
// {
// return $this->methodReflection->getReturnType();
// }

/**
* @return \PHPStan\Reflection\ParametersAcceptor[]
*/
public function getVariants(): array
{
return $this->methodReflection->getReturnType();
return $this->methodReflection->getVariants();
}
}
29 changes: 22 additions & 7 deletions src/Reflection/ComponentHasManyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@
use Symbiote\SilverstripePHPStan\ClassHelper;
use Symbiote\SilverstripePHPStan\Type\DataListType;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Type\Type;
use PHPStan\Type\ObjectType;

class ComponentHasManyMethod implements MethodReflection
{

/**
*
*
* @var string
*/
private $name;

/**
*
*
* @var \PHPStan\Reflection\ClassReflection
*/
private $declaringClass;

/**
*
*
* @var DataListType
*/
private $returnType;

/**
* @var FunctionVariant[]|null
*/
private $variants;

public function __construct(string $name, ClassReflection $declaringClass, ObjectType $type)
{
$this->name = $name;
Expand All @@ -45,7 +46,7 @@ public function getDeclaringClass(): ClassReflection
return $this->declaringClass;
}

public function getPrototype(): MethodReflection
public function getPrototype(): ClassMemberReflection
{
return $this;
}
Expand Down Expand Up @@ -84,4 +85,18 @@ public function getReturnType(): Type
{
return $this->returnType;
}

public function getVariants(): array
{
if ($this->variants === null) {
$this->variants = [
new FunctionVariant(
$this->getParameters(),
$this->isVariadic(),
$this->getReturnType()
),
];
}
return $this->variants;
}
}
29 changes: 22 additions & 7 deletions src/Reflection/ComponentHasOneMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Type\Type;
use PHPStan\Type\ObjectType;

class ComponentHasOneMethod implements MethodReflection
{

/**
*
*
* @var string
*/
private $name;

/**
*
*
* @var \PHPStan\Reflection\ClassReflection
*/
private $declaringClass;

/**
*
*
* @var ObjectType
*/
private $returnType;

/**
* @var FunctionVariant[]|null
*/
private $variants;

public function __construct(string $name, ClassReflection $declaringClass, ObjectType $type)
{
$this->name = $name;
Expand All @@ -43,7 +44,7 @@ public function getDeclaringClass(): ClassReflection
return $this->declaringClass;
}

public function getPrototype(): MethodReflection
public function getPrototype(): ClassMemberReflection
{
return $this;
}
Expand Down Expand Up @@ -82,4 +83,18 @@ public function getReturnType(): Type
{
return $this->returnType;
}

public function getVariants(): array
{
if ($this->variants === null) {
$this->variants = [
new FunctionVariant(
$this->getParameters(),
$this->isVariadic(),
$this->getReturnType()
),
];
}
return $this->variants;
}
}
23 changes: 22 additions & 1 deletion src/Reflection/ComponentManyManyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Symbiote\SilverstripePHPStan\Type\DataListType;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Type\Type;
use PHPStan\Type\ObjectType;

Expand Down Expand Up @@ -33,6 +35,11 @@ class ComponentManyManyMethod implements MethodReflection
*/
private $returnType;

/**
* @var FunctionVariant[]|null
*/
private $variants;

public function __construct(string $name, ClassReflection $declaringClass, ObjectType $type)
{
$this->name = $name;
Expand All @@ -45,7 +52,7 @@ public function getDeclaringClass(): ClassReflection
return $this->declaringClass;
}

public function getPrototype(): MethodReflection
public function getPrototype(): ClassMemberReflection
{
return $this;
}
Expand Down Expand Up @@ -84,4 +91,18 @@ public function getReturnType(): Type
{
return $this->returnType;
}

public function getVariants(): array
{
if ($this->variants === null) {
$this->variants = [
new FunctionVariant(
$this->getParameters(),
$this->isVariadic(),
$this->getReturnType()
),
];
}
return $this->variants;
}
}
2 changes: 1 addition & 1 deletion src/Reflection/MethodClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
return $this->methods[$classReflection->getName()][strtolower($methodName)];
}

public function setBroker(Broker $broker)
public function setBroker(Broker $broker): void
{
$this->broker = $broker;
}
Expand Down
Loading

0 comments on commit 1ab1ca5

Please sign in to comment.