diff --git a/.phpstan-baseline.php b/.phpstan-baseline.php index d26b10496ce..c38b7f0182b 100644 --- a/.phpstan-baseline.php +++ b/.phpstan-baseline.php @@ -1,72 +1,6 @@ '#^Cannot access constant class on object\\|false\\.$#', - 'count' => 6, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: staticProperty.nonObject - 'message' => '#^Cannot access static property \\$rightname on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method add\\(\\) on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method check\\(\\) on object\\|false\\.$#', - 'count' => 5, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method delete\\(\\) on object\\|false\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method getLinkURL\\(\\) on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method redirectToList\\(\\) on object\\|false\\.$#', - 'count' => 3, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method restore\\(\\) on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: method.nonObject - 'message' => '#^Cannot call method update\\(\\) on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: staticMethod.nonObject - 'message' => '#^Cannot call static method displayFullPageForItem\\(\\) on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; -$ignoreErrors[] = [ - // identifier: staticMethod.nonObject - 'message' => '#^Cannot call static method getDefinition\\(\\) on object\\|false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/front/asset/asset.form.php', -]; $ignoreErrors[] = [ // identifier: booleanOr.alwaysFalse 'message' => '#^Result of \\|\\| is always false\\.$#', @@ -2001,7 +1935,7 @@ ]; $ignoreErrors[] = [ // identifier: return.type - 'message' => '#^Method Glpi\\\\Asset\\\\Asset\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\Asset\\)\\|false but returns object\\.$#', + 'message' => '#^Method Glpi\\\\Asset\\\\Asset\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\Asset\\)\\|false but returns Glpi\\\\Asset\\\\Asset\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Glpi/Asset/Asset.php', ]; @@ -2019,13 +1953,13 @@ ]; $ignoreErrors[] = [ // identifier: return.type - 'message' => '#^Method Glpi\\\\Asset\\\\AssetModel\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetModel\\)\\|false but returns CommonDBTM\\.$#', + 'message' => '#^Method Glpi\\\\Asset\\\\AssetModel\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetModel\\)\\|false but returns Glpi\\\\Asset\\\\AssetModel\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Glpi/Asset/AssetModel.php', ]; $ignoreErrors[] = [ // identifier: return.type - 'message' => '#^Method Glpi\\\\Asset\\\\AssetType\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetType\\)\\|false but returns CommonDBTM\\.$#', + 'message' => '#^Method Glpi\\\\Asset\\\\AssetType\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetType\\)\\|false but returns Glpi\\\\Asset\\\\AssetType\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Glpi/Asset/AssetType.php', ]; diff --git a/front/asset/asset.form.php b/front/asset/asset.form.php index 04a346649ab..f68cc25abca 100644 --- a/front/asset/asset.form.php +++ b/front/asset/asset.form.php @@ -44,6 +44,9 @@ if (array_key_exists('id', $_REQUEST) && !Asset::isNewId($_REQUEST['id'])) { $asset = Asset::getById($_REQUEST['id']); + if ($asset === false) { + $asset = null; + } } else { $definition = new AssetDefinition(); $classname = array_key_exists('class', $_GET) && $definition->getFromDBBySystemName((string)$_GET['class']) diff --git a/src/Glpi/Asset/AssetDefinition.php b/src/Glpi/Asset/AssetDefinition.php index d6a6efee921..c7c0deb0c34 100644 --- a/src/Glpi/Asset/AssetDefinition.php +++ b/src/Glpi/Asset/AssetDefinition.php @@ -48,7 +48,6 @@ use Glpi\Search\SearchOption; use Profile; use ProfileRight; -use RuleDictionnaryDropdownCollection; use Session; final class AssetDefinition extends CommonDBTM @@ -861,6 +860,7 @@ public static function getSpecificValueToSelect($field, $name = '', $values = '' * * @param bool $with_namespace * @return string + * @phpstan-return class-string<\Glpi\Asset\Asset> */ public function getAssetClassName(bool $with_namespace = true): string { @@ -877,7 +877,8 @@ public function getAssetClassName(bool $with_namespace = true): string * Get the definition's concrete asset model class name. * * @param bool $with_namespace - * @return class-string + * @return string + * @phpstan-return class-string<\Glpi\Asset\AssetModel> */ public function getAssetModelClassName(bool $with_namespace = true): string { @@ -888,7 +889,8 @@ public function getAssetModelClassName(bool $with_namespace = true): string * Get the definition's concrete asset type class name. * * @param bool $with_namespace - * @return class-string + * @return string + * @phpstan-return class-string<\Glpi\Asset\AssetType> */ public function getAssetTypeClassName(bool $with_namespace = true): string { @@ -899,7 +901,8 @@ public function getAssetTypeClassName(bool $with_namespace = true): string * Get the definition's concrete asset model dictionary class name. * * @param bool $with_namespace - * @return class-string + * @return string + * @phpstan-return class-string<\Glpi\Asset\RuleDictionaryModel> */ public function getAssetModelDictionaryClassName(bool $with_namespace = true): string { @@ -914,7 +917,8 @@ public function getAssetModelDictionaryClassName(bool $with_namespace = true): s * Get the definition's concrete asset model dictionary collection class name. * * @param bool $with_namespace - * @return class-string + * @return string + * @phpstan-return class-string<\Glpi\Asset\RuleDictionaryModelCollection> */ public function getAssetModelDictionaryCollectionClassName(bool $with_namespace = true): string { @@ -929,7 +933,8 @@ public function getAssetModelDictionaryCollectionClassName(bool $with_namespace * Get the definition's concrete asset type dictionary class name. * * @param bool $with_namespace - * @return class-string + * @return string + * @phpstan-return class-string<\Glpi\Asset\RuleDictionaryType> */ public function getAssetTypeDictionaryClassName(bool $with_namespace = true): string { @@ -944,7 +949,8 @@ public function getAssetTypeDictionaryClassName(bool $with_namespace = true): st * Get the definition's concrete asset type dictionary collection class name. * * @param bool $with_namespace - * @return class-string + * @return string + * @phpstan-return class-string<\Glpi\Asset\RuleDictionaryTypeCollection> */ public function getAssetTypeDictionaryCollectionClassName(bool $with_namespace = true): string {