Fix phpstan issues

main
Jordi Boggiano 2 years ago
parent 27a449eaf7
commit be4b70ce79
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

14
composer.lock generated

@ -695,23 +695,23 @@
},
{
"name": "seld/jsonlint",
"version": "1.8.9",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/jsonlint.git",
"reference": "d9a308b84277a7dd651ba89bf5ed37b88497b171"
"reference": "4211420d25eba80712bff236a98960ef68b866b7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/d9a308b84277a7dd651ba89bf5ed37b88497b171",
"reference": "d9a308b84277a7dd651ba89bf5ed37b88497b171",
"url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/4211420d25eba80712bff236a98960ef68b866b7",
"reference": "4211420d25eba80712bff236a98960ef68b866b7",
"shasum": ""
},
"require": {
"php": "^5.3 || ^7.0 || ^8.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.59",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^8.5.13"
},
"bin": [
@ -743,7 +743,7 @@
],
"support": {
"issues": "https://github.com/Seldaek/jsonlint/issues",
"source": "https://github.com/Seldaek/jsonlint/tree/1.8.9"
"source": "https://github.com/Seldaek/jsonlint/tree/1.9.0"
},
"funding": [
{
@ -755,7 +755,7 @@
"type": "tidelift"
}
],
"time": "2022-03-31T11:30:35+00:00"
"time": "2022-04-01T13:37:23+00:00"
},
{
"name": "seld/phar-utils",

@ -91,7 +91,7 @@ class AutoloadGenerator
*/
public function setDevMode(bool $devMode = true)
{
$this->devMode = (bool) $devMode;
$this->devMode = $devMode;
}
/**
@ -102,7 +102,7 @@ class AutoloadGenerator
*/
public function setClassMapAuthoritative(bool $classMapAuthoritative)
{
$this->classMapAuthoritative = (bool) $classMapAuthoritative;
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
@ -114,8 +114,8 @@ class AutoloadGenerator
*/
public function setApcu(bool $apcu, ?string $apcuPrefix = null)
{
$this->apcu = (bool) $apcu;
$this->apcuPrefix = $apcuPrefix !== null ? (string) $apcuPrefix : $apcuPrefix;
$this->apcu = $apcu;
$this->apcuPrefix = $apcuPrefix !== null ? $apcuPrefix : $apcuPrefix;
}
/**
@ -126,7 +126,7 @@ class AutoloadGenerator
*/
public function setRunScripts(bool $runScripts = true)
{
$this->runScripts = (bool) $runScripts;
$this->runScripts = $runScripts;
}
/**
@ -191,7 +191,7 @@ class AutoloadGenerator
}
$this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(
'optimize' => (bool) $scanPsrPackages,
'optimize' => $scanPsrPackages,
));
}

@ -505,10 +505,10 @@ class Config
/**
* Replaces {$refs} inside a config string
*
* @param string|int|null $value a config string that can contain {$refs-to-other-config}
* @param int $flags Options (see class constants)
* @param string|mixed $value a config string that can contain {$refs-to-other-config}
* @param int $flags Options (see class constants)
*
* @return string|int|null
* @return string|mixed
*/
private function process($value, int $flags)
{

@ -182,7 +182,7 @@ class Factory
// load global config
$file = new JsonFile($config->get('home').'/config.json');
if ($file->exists()) {
if ($io) {
if ($io instanceof IOInterface) {
$io->writeError('Loading config file ' . $file->getPath(), true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $file);
@ -209,7 +209,7 @@ class Factory
// load global auth file
$file = new JsonFile($config->get('home').'/auth.json');
if ($file->exists()) {
if ($io) {
if ($io instanceof IOInterface) {
$io->writeError('Loading config file ' . $file->getPath(), true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $file, JsonFile::AUTH_SCHEMA);
@ -221,11 +221,11 @@ class Factory
if ($composerAuthEnv = Platform::getEnv('COMPOSER_AUTH')) {
$authData = json_decode($composerAuthEnv);
if (null === $authData) {
if ($io) {
if ($io instanceof IOInterface) {
$io->writeError('<error>COMPOSER_AUTH environment variable is malformed, should be a valid JSON object</error>');
}
} else {
if ($io) {
if ($io instanceof IOInterface) {
$io->writeError('Loading auth config from COMPOSER_AUTH', true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $authData, JsonFile::AUTH_SCHEMA, 'COMPOSER_AUTH');
@ -702,11 +702,14 @@ class Factory
if ($fileOrData instanceof JsonFile) {
$fileOrData->validateSchema($schema);
} else {
if (null === $source) {
throw new \InvalidArgumentException('$source is required to be provided if $fileOrData is arbitrary data');
}
JsonFile::validateJsonSchema($source, $fileOrData, $schema);
}
} catch (JsonValidationException $e) {
$msg = $e->getMessage().', this may result in errors and should be resolved:'.PHP_EOL.' - '.implode(PHP_EOL.' - ', $e->getErrors());
if ($io) {
if ($io instanceof IOInterface) {
$io->writeError('<warning>'.$msg.'</>');
} else {
throw new UnexpectedValueException($msg);

@ -203,7 +203,18 @@ class JsonFile
return self::validateJsonSchema($this->path, $data, $schema, $schemaFile);
}
public static function validateJsonSchema($source, $data, int $schema, ?string $schemaFile = null): bool
/**
* Validates the schema of the current json file according to composer-schema.json rules
*
* @param mixed $data Decoded JSON data to validate
* @param int $schema a JsonFile::*_SCHEMA constant
* @param string|null $schemaFile a path to the schema file
* @throws JsonValidationException
* @return true true on success
*
* @phpstan-param self::*_SCHEMA $schema
*/
public static function validateJsonSchema(string $source, $data, int $schema, ?string $schemaFile = null): bool
{
$isComposerSchemaFile = false;
if (null === $schemaFile) {

@ -58,6 +58,7 @@ class ConfigValidator
// validate json schema
$laxValid = false;
$manifest = null;
try {
$json = new JsonFile($file, null, $this->io);
$manifest = $json->read();
@ -79,12 +80,14 @@ class ConfigValidator
return array($errors, $publishErrors, $warnings);
}
$jsonParser = new JsonParser();
try {
$jsonParser->parse(file_get_contents($file), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
$details = $e->getDetails();
$warnings[] = 'Key '.$details['key'].' is a duplicate in '.$file.' at line '.$details['line'];
if (is_array($manifest)) {
$jsonParser = new JsonParser();
try {
$jsonParser->parse((string) file_get_contents($file), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
$details = $e->getDetails();
$warnings[] = 'Key '.$details['key'].' is a duplicate in '.$file.' at line '.$details['line'];
}
}
// validate actual data

Loading…
Cancel
Save