mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 11:24:31 +02:00
Fixed phpstan analysis issues and bad code that showed up with phpstan 2.0
This commit is contained in:
parent
a273acbecd
commit
946032a101
42 changed files with 98 additions and 85 deletions
|
@ -64,7 +64,7 @@ class EntityImporter
|
|||
* @phpstan-param class-string<T> $class_name
|
||||
* @param AbstractStructuralDBElement|null $parent the element which will be used as parent element for new elements
|
||||
* @param array $errors an associative array containing all validation errors
|
||||
* @param-out array<string, array{'entity': object, 'violations': ConstraintViolationListInterface}> $errors
|
||||
* @param-out list<array{'entity': object, 'violations': ConstraintViolationListInterface}> $errors
|
||||
*
|
||||
* @return AbstractNamedDBElement[] An array containing all valid imported entities (with the type $class_name)
|
||||
* @return T[]
|
||||
|
@ -133,13 +133,15 @@ class EntityImporter
|
|||
if ($repo instanceof StructuralDBElementRepository) {
|
||||
$entities = $repo->getNewEntityFromPath($new_path);
|
||||
$entity = end($entities);
|
||||
if ($entity === false) {
|
||||
throw new InvalidArgumentException('getNewEntityFromPath returned an empty array!');
|
||||
}
|
||||
} else { //Otherwise just create a new entity
|
||||
$entity = new $class_name;
|
||||
$entity->setName($name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Validate entity
|
||||
$tmp = $this->validator->validate($entity);
|
||||
//If no error occured, write entry to DB:
|
||||
|
@ -227,6 +229,11 @@ class EntityImporter
|
|||
|
||||
//Iterate over each $entity write it to DB.
|
||||
foreach ($entities as $key => $entity) {
|
||||
//Ensure that entity is a NamedDBElement
|
||||
if (!$entity instanceof AbstractNamedDBElement) {
|
||||
throw new \RuntimeException("Encountered an entity that is not a NamedDBElement!");
|
||||
}
|
||||
|
||||
//Validate entity
|
||||
$tmp = $this->validator->validate($entity);
|
||||
|
||||
|
@ -281,7 +288,7 @@ class EntityImporter
|
|||
*
|
||||
* @param File $file the file that should be used for importing
|
||||
* @param array $options options for the import process
|
||||
* @param AbstractNamedDBElement[] $entities The imported entities are returned in this array
|
||||
* @param-out AbstractNamedDBElement[] $entities The imported entities are returned in this array
|
||||
*
|
||||
* @return array<string, array{'entity': object, 'violations': ConstraintViolationListInterface}> An associative array containing an ConstraintViolationList and the entity name as key are returned,
|
||||
* if an error happened during validation. When everything was successfully, the array should be empty.
|
||||
|
@ -317,7 +324,7 @@ class EntityImporter
|
|||
* @param array $options options for the import process
|
||||
* @param-out array<string, array{'entity': object, 'violations': ConstraintViolationListInterface}> $errors
|
||||
*
|
||||
* @return array an array containing the deserialized elements
|
||||
* @return AbstractNamedDBElement[] an array containing the deserialized elements
|
||||
*/
|
||||
public function importFile(File $file, array $options = [], array &$errors = []): array
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue