Skip to content

Commit

Permalink
fixed psalm issues after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed Nov 10, 2020
1 parent 26fd182 commit d5f5993
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/ComposerRequireChecker/Cli/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Webmozart\Assert\Assert;

use function array_diff;
use function count;
Expand Down Expand Up @@ -165,8 +166,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @return array<array-key, mixed>
*
* @throws InvalidJson
* @throws NotReadable
*/
Expand All @@ -178,7 +177,10 @@ private function getCheckOptions(InputInterface $input): Options
return new Options();
}

return new Options(JsonLoader::getData($fileName));
$config = JsonLoader::getData($fileName);
Assert::isMap($config);

return new Options($config);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/ComposerRequireChecker/Cli/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Options
*/
public function __construct(array $options = [])
{
/**
* @var mixed $option
*/
foreach ($options as $key => $option) {
$methodName = 'set' . $this->getCamelCase($key);
if (! method_exists($this, $methodName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use SplFileInfo;
use Traversable;

use function assert;
use function implode;
use function preg_match;
use function preg_quote;
Expand Down Expand Up @@ -54,7 +53,6 @@ private function filterFilesByExtension(Traversable $files, string $fileExtensio
$blacklistMatcher = '{(' . implode('|', $this->prepareBlacklistPatterns($blacklist)) . ')}';

foreach ($files as $file) {
assert($file instanceof SplFileInfo);
if ($blacklist && preg_match($blacklistMatcher, $file->getPathname())) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
use function array_key_exists;
use function assert;
use function dirname;
use function file_get_contents;
use function is_string;
use function json_decode;

final class LocateComposerPackageDirectDependenciesSourceFiles
{
public function __invoke(string $composerJsonPath): Generator
{
$packageDir = dirname($composerJsonPath);

$composerJson = json_decode(file_get_contents($composerJsonPath), true);
$composerJson = JsonLoader::getData($composerJsonPath);
$configVendorDir = $composerJson['config']['vendor-dir'] ?? 'vendor';
assert(is_string($configVendorDir));
$vendorDirs = [];
Expand Down
5 changes: 4 additions & 1 deletion src/ComposerRequireChecker/JsonLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class JsonLoader
*/
public static function getData(string $path): array
{
$content = self::getFileContentFromPath($path);

try {
$decodedData = json_decode(self::getFileContentFromPath($path), true, 512, JSON_THROW_ON_ERROR);
$decodedData = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
Assert::isArray($decodedData);
} catch (Throwable $exception) {
throw new InvalidJson('error parsing ' . $path . ': ' . $exception->getMessage(), 0, $exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ private function recordDefinedConstDefinition(Node $node): void
return;
}

if (
$node->name->hasAttribute('namespacedName')
&& $node->name->getAttribute('namespacedName') instanceof Node\Name\FullyQualified
&& $node->name->getAttribute('namespacedName')->toString() !== 'define'
) {
return;
if ($node->name->hasAttribute('namespacedName')) {
/** @var mixed $namespacedName */
$namespacedName = $node->name->getAttribute('namespacedName');
if ($namespacedName instanceof Node\Name\FullyQualified && $namespacedName->toString() !== 'define') {
return;
}
}

if (! ($node->args[0]->value instanceof Node\Scalar\String_)) {
Expand Down
4 changes: 2 additions & 2 deletions test/ComposerRequireCheckerTest/JsonLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function testHasErrorWithInvalidFile(): void
public function testHasDataWithValidFileButNoArrayContent(): void
{
$path = __DIR__ . '/../fixtures/validJsonNotAnArray.json';
$this->expectException(InvalidJsonException::class);
new JsonLoader($path);
$this->expectException(InvalidJson::class);
JsonLoader::getData($path);
}

public function testHasDataWithValidFile(): void
Expand Down

0 comments on commit d5f5993

Please sign in to comment.