Skip to content

Commit

Permalink
Merge branch 'gennadigennadigennadi/code-style-v2' into 3.2.x
Browse files Browse the repository at this point in the history
Signed-off-by: tux-rampage <tuxrampage@gmail.com>
  • Loading branch information
tux-rampage committed Oct 12, 2020
2 parents cd20d42 + 1797c2a commit da9ca8d
Show file tree
Hide file tree
Showing 89 changed files with 896 additions and 886 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
/.phpcs-cache
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -34,7 +34,7 @@
},
"require-dev": {
"container-interop/container-interop": "^1.2.0",
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-coding-standard": "^2",
"laminas/laminas-servicemanager": "^3.4",
"mikey179/vfsstream": "^1.6.7",
"phpstan/phpstan": "^0.12",
Expand Down
14 changes: 12 additions & 2 deletions phpcs.xml
@@ -1,6 +1,15 @@
<?xml version="1.0"?>
<ruleset name="Laminas Coding Standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>


<!--
Don't make it bail at the file level deprecation of AbstactInjection (Intented side effect).
Expand All @@ -18,4 +27,5 @@
<file>test</file>

<exclude-pattern><![CDATA[*/test/_files/*]]></exclude-pattern>
<rule ref="LaminasCodingStandard"/>
</ruleset>
71 changes: 28 additions & 43 deletions phpstan-baseline.neon
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Method Laminas\\\\Di\\\\CodeGenerator\\\\AbstractInjector\\:\\:getFactory\\(\\) has parameter \\$type with no typehint specified\\.$#"
count: 1
path: src/CodeGenerator/AbstractInjector.php

-
message: "#^Method Laminas\\\\Di\\\\CodeGenerator\\\\AbstractInjector\\:\\:create\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -126,17 +121,22 @@ parameters:
path: src/Config.php

-
message: "#^Method Laminas\\\\Di\\\\Config\\:\\:setParameters\\(\\) has no return typehint specified\\.$#"
message: "#^Method Laminas\\\\Di\\\\Config\\:\\:setParameters\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method Laminas\\\\Di\\\\Config\\:\\:setParameters\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
message: "#^Method Laminas\\\\Di\\\\Config\\:\\:ensureArrayOrArrayAccess\\(\\) has parameter \\$options with generic interface ArrayAccess but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/Config.php

-
message: "#^Method Laminas\\\\Di\\\\Config\\:\\:ensureArrayOrArrayAccess\\(\\) has parameter \\$options with no typehint specified\\.$#"
message: "#^Method Laminas\\\\Di\\\\Config\\:\\:ensureArrayOrArrayAccess\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/Config.php

Expand Down Expand Up @@ -165,43 +165,28 @@ parameters:
count: 1
path: src/ConfigProvider.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:canCreate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/Container/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:canCreate\\(\\) has parameter \\$requestedName with no typehint specified\\.$#"
count: 1
path: src/Container/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:create\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/Container/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:create\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Container/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:__invoke\\(\\) has no return typehint specified\\.$#"
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:__invoke\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Container/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:__invoke\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
message: "#^Method Laminas\\\\Di\\\\Container\\\\ServiceManager\\\\AutowireFactory\\:\\:__invoke\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Container/AutowireFactory.php
path: src/Container/ServiceManager/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\AutowireFactory\\:\\:__invoke\\(\\) has parameter \\$requestedName with no typehint specified\\.$#"
count: 1
path: src/Container/AutowireFactory.php
message: "#^Return type \\(bool\\) of method Laminas\\\\Di\\\\Container\\\\ServiceManager\\\\AutowireFactory\\:\\:__invoke\\(\\) should be compatible with return type \\(object\\) of method Laminas\\\\ServiceManager\\\\Factory\\\\FactoryInterface\\:\\:__invoke\\(\\)$#"
count: 2
path: src/Container/ServiceManager/AutowireFactory.php

-
message: "#^Method Laminas\\\\Di\\\\Container\\\\ServiceManager\\\\AutowireFactory\\:\\:__invoke\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
message: "#^Method Laminas\\\\Di\\\\Container\\\\ServiceManager\\\\AutowireFactory\\:\\:__invoke\\(\\) should return bool but returns object\\.$#"
count: 1
path: src/Container/ServiceManager/AutowireFactory.php

Expand Down Expand Up @@ -230,11 +215,21 @@ parameters:
count: 1
path: src/Definition/Reflection/ClassDefinition.php

-
message: "#^Method Laminas\\\\Di\\\\Definition\\\\Reflection\\\\ClassDefinition\\:\\:reflectSupertypes\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/Definition/Reflection/ClassDefinition.php

-
message: "#^Method Laminas\\\\Di\\\\Definition\\\\Reflection\\\\ClassDefinition\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
count: 1
path: src/Definition/Reflection/ClassDefinition.php

-
message: "#^Method Laminas\\\\Di\\\\Definition\\\\Reflection\\\\ClassDefinition\\:\\:reflectParameters\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/Definition/Reflection/ClassDefinition.php

-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -276,17 +271,12 @@ parameters:
path: src/InjectorInterface.php

-
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:__construct\\(\\) has parameter \\$config with no typehint specified\\.$#"
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:__construct\\(\\) has parameter \\$config with generic interface ArrayAccess but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/LegacyConfig.php

-
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:prepareParametersArray\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/LegacyConfig.php

-
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:prepareParametersArray\\(\\) has parameter \\$parameters with no typehint specified\\.$#"
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:__construct\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/LegacyConfig.php

Expand All @@ -296,7 +286,7 @@ parameters:
path: src/LegacyConfig.php

-
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:configureInstance\\(\\) has parameter \\$config with no typehint specified\\.$#"
message: "#^Method Laminas\\\\Di\\\\LegacyConfig\\:\\:configureInstance\\(\\) has parameter \\$config with no value type specified in iterable type iterable\\.$#"
count: 1
path: src/LegacyConfig.php

Expand Down Expand Up @@ -340,8 +330,3 @@ parameters:
count: 1
path: src/Resolver/ValueInjection.php

-
message: "#^Method Laminas\\\\Di\\\\Resolver\\\\ValueInjection\\:\\:getValue\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/Resolver/ValueInjection.php

35 changes: 14 additions & 21 deletions src/CodeGenerator/AbstractInjector.php
Expand Up @@ -19,32 +19,24 @@
*/
abstract class AbstractInjector implements InjectorInterface
{
/**
* @var string[]|FactoryInterface[]
*/
/** @var string[]|FactoryInterface[] */
protected $factories = [];

/**
* @var FactoryInterface[]
*/
/** @var FactoryInterface[] */
private $factoryInstances = [];

/**
* @var ContainerInterface
*/
/** @var ContainerInterface */
private $container;

/**
* @var InjectorInterface
*/
/** @var InjectorInterface */
private $injector;

/**
* {@inheritDoc}
*/
public function __construct(InjectorInterface $injector, ContainerInterface $container = null)
public function __construct(InjectorInterface $injector, ?ContainerInterface $container = null)
{
$this->injector = $injector;
$this->injector = $injector;
$this->container = $container ?: new DefaultContainer($this);

$this->loadFactoryList();
Expand All @@ -53,32 +45,33 @@ public function __construct(InjectorInterface $injector, ContainerInterface $con
/**
* Init factory list
*/
abstract protected function loadFactoryList() : void;
abstract protected function loadFactoryList(): void;

private function setFactory(string $type, FactoryInterface $factory) : void
private function setFactory(string $type, FactoryInterface $factory): void
{
$this->factoryInstances[$type] = $factory;
}

private function getFactory($type) : FactoryInterface
private function getFactory(string $type): FactoryInterface
{
if (isset($this->factoryInstances[$type])) {
return $this->factoryInstances[$type];
}

$factoryClass = $this->factories[$type];
$factory = ($factoryClass instanceof FactoryInterface) ? $factoryClass : new $factoryClass();
$factory = $factoryClass instanceof FactoryInterface ? $factoryClass : new $factoryClass();

$this->setFactory($type, $factory);

return $factory;
}

public function canCreate(string $name) : bool
public function canCreate(string $name): bool
{
return (isset($this->factories[$name]) || $this->injector->canCreate($name));
return isset($this->factories[$name]) || $this->injector->canCreate($name);
}

/** @return mixed */
public function create(string $name, array $options = [])
{
if (isset($this->factories[$name])) {
Expand Down
21 changes: 10 additions & 11 deletions src/CodeGenerator/AutoloadGenerator.php
Expand Up @@ -16,6 +16,7 @@

use function array_keys;
use function array_map;
use function assert;
use function file_get_contents;
use function implode;
use function is_string;
Expand All @@ -29,19 +30,17 @@ class AutoloadGenerator
use GeneratorTrait;

private const CLASS_TEMPLATE = __DIR__ . '/../../templates/autoloader-class.template';
private const FILE_TEMPLATE = __DIR__ . '/../../templates/autoloader-file.template';
private const FILE_TEMPLATE = __DIR__ . '/../../templates/autoloader-file.template';

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

public function __construct(string $namespace)
{
$this->namespace = $namespace;
}

private function writeFile(string $filename, string $code) : void
private function writeFile(string $filename, string $code): void
{
try {
$file = new SplFileObject($filename, 'w');
Expand All @@ -51,7 +50,7 @@ private function writeFile(string $filename, string $code) : void
}
}

private function buildFromTemplate(string $templateFile, string $outputFile, array $replacements) : void
private function buildFromTemplate(string $templateFile, string $outputFile, array $replacements): void
{
$template = file_get_contents($templateFile);

Expand All @@ -66,7 +65,7 @@ private function buildFromTemplate(string $templateFile, string $outputFile, arr
);
}

private function generateClassmapCode(array &$classmap) : string
private function generateClassmapCode(array &$classmap): string
{
$lines = array_map(
function (string $class, string $file): string {
Expand All @@ -84,15 +83,15 @@ function (string $class, string $file): string {
return implode($indentation, $lines);
}

private function generateAutoloaderClass(array &$classmap) : void
private function generateAutoloaderClass(array &$classmap): void
{
$this->buildFromTemplate(self::CLASS_TEMPLATE, 'Autoloader.php', [
'%namespace%' => $this->namespace ? sprintf("namespace %s;\n", $this->namespace) : '',
'%classmap%' => $this->generateClassmapCode($classmap),
'%classmap%' => $this->generateClassmapCode($classmap),
]);
}

private function generateAutoloadFile() : void
private function generateAutoloadFile(): void
{
$this->buildFromTemplate(self::FILE_TEMPLATE, 'autoload.php', [
'%namespace%' => $this->namespace ? sprintf("namespace %s;\n", $this->namespace) : '',
Expand All @@ -102,7 +101,7 @@ private function generateAutoloadFile() : void
/**
* @param string[] $classmap
*/
public function generate(array &$classmap) : void
public function generate(array &$classmap): void
{
$this->ensureOutputDirectory();
$this->generateAutoloaderClass($classmap);
Expand Down

0 comments on commit da9ca8d

Please sign in to comment.