Skip to content

Commit

Permalink
Merge pull request #137 from shochdoerfer/feature/phpstan
Browse files Browse the repository at this point in the history
Re-introduce PHPStan
  • Loading branch information
shochdoerfer committed Mar 14, 2021
2 parents 051199e + 21693d5 commit c3659ff
Show file tree
Hide file tree
Showing 32 changed files with 454 additions and 218 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Codesniffer
run: composer cs-check

- name: Static code analysis
run: composer analyze

- name: Unittests
if: matrix.coveralls == false
run: composer test
Expand Down
15 changes: 11 additions & 4 deletions composer.json
Expand Up @@ -3,6 +3,9 @@
"description": "Dependency Injection Container",
"minimum-stability": "stable",
"license": "Apache-2.0",
"config": {
"sort-packages": true
},
"authors": [
{
"name": "Stephan Hochdörfer",
Expand All @@ -18,11 +21,15 @@
"bitexpert/slf4psrlog": "^0.1.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5.2",
"squizlabs/php_codesniffer": "^3.5.8",
"monolog/monolog": "^2.2.0",
"bookdown/bookdown": "@dev",
"mikey179/vfsstream": "^1.6",
"bookdown/bookdown": "@dev"
"monolog/monolog": "^2.2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.81",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpstan/phpstan-strict-rules": "^0.12.9",
"phpunit/phpunit": "^9.5.2",
"squizlabs/php_codesniffer": "^3.5.8"
},
"autoload": {
"psr-4": {
Expand Down
213 changes: 212 additions & 1 deletion composer.lock

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

14 changes: 12 additions & 2 deletions phpstan.neon.dist
@@ -1,8 +1,18 @@
parameters:
level: max
checkGenericClassInNonGenericObjectType: false
fileExtensions:
- php
paths:
- ./src
- ./tests
excludes_analyse:
- %currentWorkingDirectory%/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php
- %currentWorkingDirectory%/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php
- %currentWorkingDirectory%/tests/bitExpert/Disco/Config/*.php
- %currentWorkingDirectory%/tests/bitExpert/Disco/Helper/*.php
ignoreErrors:
-
message: '~Variable method call on bitExpert\\Disco\\Proxy\\Configuration\\AliasContainerInterface~'
path: src/bitExpert/Disco/AnnotationBeanFactory.php
-
message: '~Parameter #1 \$callback of function spl_autoload_register expects~'
path: src/bitExpert/Disco/BeanFactoryConfiguration.php
16 changes: 4 additions & 12 deletions src/bitExpert/Disco/AnnotationBeanFactory.php
Expand Up @@ -30,8 +30,8 @@ class AnnotationBeanFactory implements BeanFactory
/**
* Creates a new {@link \bitExpert\Disco\BeanFactory}.
*
* @param string $configClassName
* @param array $parameters
* @param class-string<Object> $configClassName
* @param array<string, mixed> $parameters
* @param BeanFactoryConfiguration $config
*/
public function __construct($configClassName, array $parameters = [], BeanFactoryConfiguration $config = null)
Expand All @@ -49,12 +49,8 @@ public function __construct($configClassName, array $parameters = [], BeanFactor
* @throws BeanException
* @throws BeanNotFoundException
*/
public function get($id)
public function get(string $id)
{
if (!is_string($id) || empty($id)) {
throw new BeanException('Id must be a non-empty string.');
}

$instance = null;

try {
Expand Down Expand Up @@ -83,12 +79,8 @@ public function get($id)
/**
* {@inheritDoc}
*/
public function has($id)
public function has(string $id)
{
if (!is_string($id) || empty($id)) {
return false;
}

return is_callable([$this->beanConfig, $id]) || $this->beanConfig->hasAlias($id);
}
}
6 changes: 3 additions & 3 deletions src/bitExpert/Disco/Annotations/Alias.php
Expand Up @@ -27,7 +27,7 @@
final class Alias
{
/**
* @var string
* @var ?string
*/
private $name;

Expand All @@ -39,7 +39,7 @@ final class Alias
/**
* Creates a new {@link \bitExpert\Disco\Annotations\Bean\Alias}.
*
* @param array $attributes
* @param array<string, array<string, mixed>> $attributes
* @throws AnnotationException
*/
public function __construct(array $attributes = [])
Expand All @@ -58,7 +58,7 @@ public function __construct(array $attributes = [])
$this->name = $attributes['value']['name'];
}

if (!$this->type && !$this->name) {
if (!$this->type && (!is_string($this->name) || $this->name === '')) {
throw new AnnotationException('Alias should either be a named alias or a type alias!');
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/bitExpert/Disco/Annotations/Bean.php
Expand Up @@ -51,8 +51,7 @@ final class Bean extends ParameterAwareAnnotation
/**
* Creates a new {@link \bitExpert\Disco\Annotations\Bean}.
*
* @param array $attributes
* @throws AnnotationException
* @param array<string, array<string, mixed>> $attributes
*/
public function __construct(array $attributes = [])
{
Expand Down
3 changes: 1 addition & 2 deletions src/bitExpert/Disco/Annotations/BeanPostProcessor.php
Expand Up @@ -28,8 +28,7 @@ final class BeanPostProcessor extends ParameterAwareAnnotation
/**
* Creates a new {@link \bitExpert\Disco\Annotations\BeanPostProcessor}.
*
* @param array $attributes
* @throws AnnotationException
* @param array<string, array<string, mixed>> $attributes
*/
public function __construct(array $attributes = [])
{
Expand Down

0 comments on commit c3659ff

Please sign in to comment.