Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
updated discovery-common
Browse files Browse the repository at this point in the history
added coding-standard
fixes on cs and phpstan
  • Loading branch information
danielbannert committed Jul 27, 2018
1 parent f9654b0 commit ed3084f
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 67 deletions.
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
"ext-mbstring": "*"
},
"require-dev": {
"composer/composer": "^1.6",
"composer/composer": "^1.6.0",
"mockery/mockery": "^1.0.0",
"narrowspark/discovery-common": "^0.1",
"narrowspark/php-cs-fixer-config": "^2.1.0",
"narrowspark/discovery-common": "^0.1.7",
"narrowspark/coding-standard": "^1.0.0",
"narrowspark/testing-helper": "^6.0.0",
"phpstan/phpstan": "^0.9.0",
"phpstan/phpstan-phpunit": "^0.9.0",
"phpunit/phpunit": "^7.0.0"
"phpunit/phpunit": "^7.2.0"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -51,7 +49,8 @@
"scripts": {
"coverage": "phpunit --coverage-html=\"build/logs\"",
"cs": "php-cs-fixer fix",
"phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1"
"phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1",
"test": "phpunit"
},
"support": {
"issues": "https://github.com/narrowspark/configurators/issues",
Expand Down
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
includes:
# - vendor/pepakriz/phpstan-exception-rules/extension.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
# - vendor/phpstan/phpstan-strict-rules/rules.neon
# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

parameters:
autoload_directories:
- %currentWorkingDirectory%/src/

ignoreErrors:
- '#Function opcache_invalidate not found#'
10 changes: 6 additions & 4 deletions src/AbstractClassConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function unconfigure(PackageContract $package): void

$envs = \array_keys($sortedClasses);

/** @param string[] $contents */
$contents = [];

foreach ($envs as $env) {
Expand All @@ -101,7 +102,7 @@ public function unconfigure(PackageContract $package): void
continue;
}

$contents[$env] = \file_get_contents($filePath);
$contents[$env] = (string) \file_get_contents($filePath);

\unlink($filePath);
}
Expand All @@ -119,9 +120,10 @@ public function unconfigure(PackageContract $package): void
$spaces = \str_repeat(' ', static::$spaceMultiplication);

foreach ($contents as $key => $content) {
$content = \str_replace([$spaces . '/** > ' . $package->getName() . " **/\n", $spaces . '/** ' . $package->getName() . " < **/\n"], '', $content);

$this->dump($this->getConfFile($key), $content);
$this->dump(
$this->getConfFile((string) $key),
\str_replace([$spaces . '/** > ' . $package->getName() . " **/\n", $spaces . '/** ' . $package->getName() . " < **/\n"], '', $content)
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ProxyConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function getName(): string
protected function generateFileContent(PackageContract $package, string $filePath, array $classes, string $env): string
{
if (\file_exists($filePath)) {
$content = \file_get_contents($filePath);
$content = (string) \file_get_contents($filePath);

\unlink($filePath);
} else {
Expand All @@ -59,7 +59,7 @@ protected function generateFileContent(PackageContract $package, string $filePat
$content = $this->doInsertStringBeforePosition(
$content,
$this->buildClassNamesContent($package, $classes, $env),
$endPositionOfAliasesArray
(int) $endPositionOfAliasesArray
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ServiceProviderConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function getName(): string
protected function generateFileContent(PackageContract $package, string $filePath, array $classes, string $type): string
{
if (\file_exists($filePath)) {
$content = \file_get_contents($filePath);
$content = (string) \file_get_contents($filePath);

\unlink($filePath);
} else {
Expand All @@ -51,7 +51,7 @@ protected function generateFileContent(PackageContract $package, string $filePat
$content = $this->doInsertStringBeforePosition(
$content,
$this->buildClassNamesContent($package, $classes, $type),
\mb_strpos($content, '];')
(int) \mb_strpos($content, '];')
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/GetSortedClassesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getSortedClasses(PackageContract $package, string $key): arra
$class = \mb_strpos($provider, '::class') !== false ? $provider : $provider . '::class';

foreach ($environments as $environment) {
$sortedProviders[$environment][$class] = '\\' . \ltrim($class, '\\');
$sortedProviders[$environment][$class] = '\\' . \ltrim((string) $class, '\\');
}
}

Expand Down
57 changes: 30 additions & 27 deletions tests/ProxyConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Narrowspark\Discovery\Configurator\ProxyConfigurator;
use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;

class ProxyConfiguratorTest extends MockeryTestCase
/**
* @internal
*/
final class ProxyConfiguratorTest extends MockeryTestCase
{
use PhpFileMarkerTrait;

Expand Down Expand Up @@ -93,11 +96,11 @@ public function testConfigureWithGlobalProxy(): void

$this->configurator->configure($package);

self::assertTrue($this->isFileMarked('test', $this->globalPath));
static::assertTrue($this->isFileMarked('test', $this->globalPath));

$array = include $this->globalPath;

self::assertSame(self::class, $array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']);
static::assertSame(self::class, $array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']);
}

public function testConfigureWithGlobalAndLocalProxy(): void
Expand All @@ -118,16 +121,16 @@ public function testConfigureWithGlobalAndLocalProxy(): void

$this->configurator->configure($package);

self::assertTrue($this->isFileMarked('test', $this->globalPath));
self::assertTrue($this->isFileMarked('test', $this->localPath));
static::assertTrue($this->isFileMarked('test', $this->globalPath));
static::assertTrue($this->isFileMarked('test', $this->localPath));

$array = include $this->globalPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));

$array = include $this->localPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
}

public function testSkipMarkedFiles(): void
Expand All @@ -150,11 +153,11 @@ public function testSkipMarkedFiles(): void

$array = include $this->globalPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));

$this->configurator->configure($package);

self::assertCount(1, $array['viserio']['staticalproxy']['aliases']);
static::assertCount(1, $array['viserio']['staticalproxy']['aliases']);
}

public function testUpdateExistedFileWithGlobalProxy(): void
Expand All @@ -175,11 +178,11 @@ public function testUpdateExistedFileWithGlobalProxy(): void

$this->configurator->configure($package);

self::assertTrue($this->isFileMarked('test', $this->globalPath));
static::assertTrue($this->isFileMarked('test', $this->globalPath));

$array = include $this->globalPath;

self::assertSame(self::class, $array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']);
static::assertSame(self::class, $array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']);

$package = new Package(
'test2',
Expand All @@ -197,12 +200,12 @@ public function testUpdateExistedFileWithGlobalProxy(): void

$this->configurator->configure($package);

self::assertTrue($this->isFileMarked('test2', $this->globalPath));
static::assertTrue($this->isFileMarked('test2', $this->globalPath));

$array = include $this->globalPath;

self::assertSame(self::class, $array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']);
self::assertSame(Package::class, $array['viserio']['staticalproxy']['aliases']['Package']);
static::assertSame(self::class, $array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']);
static::assertSame(Package::class, $array['viserio']['staticalproxy']['aliases']['Package']);
}

public function testUpdateAExistedFileWithGlobalAndLocalProxy(): void
Expand All @@ -225,11 +228,11 @@ public function testUpdateAExistedFileWithGlobalAndLocalProxy(): void

$array = include $this->globalPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));

$array = include $this->localPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));

$package = new Package(
'test2',
Expand All @@ -249,13 +252,13 @@ public function testUpdateAExistedFileWithGlobalAndLocalProxy(): void

$array = include $this->globalPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
self::assertSame(Package::class, \end($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(Package::class, \end($array['viserio']['staticalproxy']['aliases']));

$array = include $this->localPath;

self::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
self::assertSame(Package::class, \end($array['viserio']['staticalproxy']['aliases']));
static::assertSame(self::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertSame(Package::class, \end($array['viserio']['staticalproxy']['aliases']));
}

public function testConfigureWithEmptyProxiesConfig(): void
Expand All @@ -275,7 +278,7 @@ public function testConfigureWithEmptyProxiesConfig(): void

$this->configurator->configure($package);

self::assertFileNotExists($this->globalPath);
static::assertFileNotExists($this->globalPath);
}

public function testUnconfigureWithGlobalProxies(): void
Expand All @@ -296,11 +299,11 @@ public function testUnconfigureWithGlobalProxies(): void

$this->configurator->configure($package);

self::assertTrue($this->isFileMarked('test', $this->globalPath));
static::assertTrue($this->isFileMarked('test', $this->globalPath));

$this->configurator->unconfigure($package);

self::assertFalse($this->isFileMarked('test', $this->globalPath));
static::assertFalse($this->isFileMarked('test', $this->globalPath));

$package = new Package(
'test2',
Expand All @@ -318,12 +321,12 @@ public function testUnconfigureWithGlobalProxies(): void

$this->configurator->configure($package);

self::assertTrue($this->isFileMarked('test2', $this->globalPath));
static::assertTrue($this->isFileMarked('test2', $this->globalPath));

$array = include $this->globalPath;

self::assertSame(Package::class, \reset($array['viserio']['staticalproxy']['aliases']));
self::assertFalse(isset($array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']));
static::assertSame(Package::class, \reset($array['viserio']['staticalproxy']['aliases']));
static::assertFalse(isset($array['viserio']['staticalproxy']['aliases']['ProxyConfiguratorTest']));
}

public function testUnconfigureAndConfigureAgain(): void
Expand All @@ -350,6 +353,6 @@ public function testUnconfigureAndConfigureAgain(): void

$array = include $this->globalPath;

self::assertCount(1, $array['viserio']['staticalproxy']['aliases']);
static::assertCount(1, $array['viserio']['staticalproxy']['aliases']);
}
}
Loading

0 comments on commit ed3084f

Please sign in to comment.