Renamed the base DBElement classes to AbstractDBElement to comply with symfony recommendations.

This commit is contained in:
Jan Böhmer 2020-02-01 19:48:07 +01:00
parent da72f5b3ec
commit 594c694ee0
62 changed files with 203 additions and 203 deletions

View file

@ -26,8 +26,8 @@ namespace App\Services;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
@ -82,7 +82,7 @@ class ElementTypeNameGenerator
* Useful when the type should be shown to user.
* Throws an exception if the class is not supported.
*
* @param DBElement|string $entity The element or class for which the label should be generated
* @param AbstractDBElement|string $entity The element or class for which the label should be generated
*
* @return string the localized label for the entity type
*
@ -113,14 +113,14 @@ class ElementTypeNameGenerator
* For example this could be something like: "Part: BC547".
* It uses getLocalizedLabel to determine the type.
*
* @param NamedDBElement $entity the entity for which the string should be generated
* @param AbstractNamedDBElement $entity the entity for which the string should be generated
* @param bool $use_html If set to true, a html string is returned, where the type is set italic
*
* @return string The localized string
*
* @throws EntityNotSupportedException when the passed entity is not supported
*/
public function getTypeNameCombination(NamedDBElement $entity, bool $use_html = false): string
public function getTypeNameCombination(AbstractNamedDBElement $entity, bool $use_html = false): string
{
$type = $this->getLocalizedTypeLabel($entity);
if ($use_html) {

View file

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\AbstractNamedDBElement;
use function in_array;
use InvalidArgumentException;
use function is_array;
@ -114,7 +114,7 @@ class EntityExporter
//If view option is not specified, then download the file.
if (! $request->get('view')) {
if ($entity instanceof NamedDBElement) {
if ($entity instanceof AbstractNamedDBElement) {
$entity_name = $entity->getName();
} elseif (is_array($entity)) {
if (empty($entity)) {

View file

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Base\StructuralDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use Symfony\Bundle\MakerBundle\Str;
use function count;
use Doctrine\ORM\EntityManagerInterface;
@ -54,17 +54,17 @@ class EntityImporter
*
* @param string $lines The list of names seperated by \n
* @param string $class_name The name of the class for which the entities should be created
* @param StructuralDBElement|null $parent the element which will be used as parent element for new elements
* @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
*
* @return StructuralDBElement[] An array containing all valid imported entities (with the type $class_name)
* @return AbstractStructuralDBElement[] An array containing all valid imported entities (with the type $class_name)
*/
public function massCreation(string $lines, string $class_name, ?StructuralDBElement $parent = null, array &$errors = []): array
public function massCreation(string $lines, string $class_name, ?AbstractStructuralDBElement $parent = null, array &$errors = []): array
{
//Expand every line to a single entry:
$names = explode("\n", $lines);
if (! is_a($class_name, StructuralDBElement::class, true)) {
if (! is_a($class_name, AbstractStructuralDBElement::class, true)) {
throw new InvalidArgumentException('$class_name must be a StructuralDBElement type!');
}
if (null !== $parent && ! is_a($parent, $class_name)) {
@ -80,7 +80,7 @@ class EntityImporter
//Skip empty lines (StrucuralDBElements must have a name)
continue;
}
/** @var StructuralDBElement $entity */
/** @var AbstractStructuralDBElement $entity */
//Create new element with given name
$entity = new $class_name();
$entity->setName($name);
@ -126,7 +126,7 @@ class EntityImporter
//Iterate over each $entity write it to DB.
foreach ($entities as $entity) {
/** @var StructuralDBElement $entity */
/** @var AbstractStructuralDBElement $entity */
//Move every imported entity to the selected parent
$entity->setParent($options['parent']);
@ -189,7 +189,7 @@ class EntityImporter
}
//The serializer has only set the children attributes. We also have to change the parent value (the real value in DB)
if ($entities[0] instanceof StructuralDBElement) {
if ($entities[0] instanceof AbstractStructuralDBElement) {
$this->correctParentEntites($entities, null);
}
@ -211,12 +211,12 @@ class EntityImporter
* This functions corrects the parent setting based on the children value of the parent.
*
* @param iterable $entities the list of entities that should be fixed
* @param null|StructuralDBElement $parent the parent, to which the entity should be set
* @param null|AbstractStructuralDBElement $parent the parent, to which the entity should be set
*/
protected function correctParentEntites(iterable $entities, $parent = null): void
{
foreach ($entities as $entity) {
/** @var StructuralDBElement $entity */
/** @var AbstractStructuralDBElement $entity */
$entity->setParent($parent);
//Do the same for the children of entity
$this->correctParentEntites($entity->getChildren(), $entity);

View file

@ -26,7 +26,7 @@ namespace App\Services;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\DBElement;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
@ -133,13 +133,13 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where info about this entity can be viewed.
*
* @param DBElement $entity The entity for which the info should be generated
* @param AbstractDBElement $entity The entity for which the info should be generated
*
* @return string The URL to the info page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/
public function infoURL(DBElement $entity): string
public function infoURL(AbstractDBElement $entity): string
{
$map = [
Part::class => 'part_info',
@ -223,13 +223,13 @@ class EntityURLGenerator
* Generates an URL to a page, where a new entity can be created, that has the same informations as the
* given entity (element cloning).
*
* @param DBElement $entity The entity for which the link should be generated
* @param AbstractDBElement $entity The entity for which the link should be generated
*
* @return string the URL to the page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/
public function cloneURL(DBElement $entity): string
public function cloneURL(AbstractDBElement $entity): string
{
$map = [
Part::class => 'part_clone',
@ -241,13 +241,13 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where all parts are listed, which are contained in the given element.
*
* @param DBElement $entity The entity for which the link should be generated
* @param AbstractDBElement $entity The entity for which the link should be generated
*
* @return string the URL to the page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/
public function listPartsURL(DBElement $entity): string
public function listPartsURL(AbstractDBElement $entity): string
{
$map = [
Category::class => 'part_list_category',
@ -260,7 +260,7 @@ class EntityURLGenerator
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
}
public function deleteURL(DBElement $entity): string
public function deleteURL(AbstractDBElement $entity): string
{
$map = [
Part::class => 'part_delete',

View file

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\Base\StructuralDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use Doctrine\ORM\EntityManagerInterface;
class StructuralElementRecursionHelper
@ -39,7 +39,7 @@ class StructuralElementRecursionHelper
/**
* Executes an function (callable) recursivly for $element and every of its children.
*
* @param StructuralDBElement $element The element on which the func should be executed
* @param AbstractStructuralDBElement $element The element on which the func should be executed
* @param callable $func The function which should be executed for each element.
* $func has the signature function(StructuralDBElement $element) : void
* @param int $max_depth The maximum depth for which should be recursivly called. So if this is set to 5, after the
@ -47,7 +47,7 @@ class StructuralElementRecursionHelper
* @param bool $call_from_bottom If set to true the bottom elements (elements with high level) will be called first.
* Set to false if you want to call the top elements first.
*/
public function execute(StructuralDBElement $element, callable $func, int $max_depth = -1, $call_from_bottom = true): void
public function execute(AbstractStructuralDBElement $element, callable $func, int $max_depth = -1, $call_from_bottom = true): void
{
//Cancel if we reached our maximal allowed level. Must be zero because -1 is infinity levels
if (0 === $max_depth) {
@ -75,15 +75,15 @@ class StructuralElementRecursionHelper
/**
* Deletes the $element and all its subelements recursivly.
*
* @param StructuralDBElement $element the element which should be deleted
* @param AbstractStructuralDBElement $element the element which should be deleted
* @param bool $flush When set to true the changes will also be flushed to DB. Set to false if you want to flush
* later.
*/
public function delete(StructuralDBElement $element, bool $flush = true): void
public function delete(AbstractStructuralDBElement $element, bool $flush = true): void
{
$em = $this->em;
$this->execute($element, static function (StructuralDBElement $element) use ($em): void {
$this->execute($element, static function (AbstractStructuralDBElement $element) use ($em): void {
$em->remove($element);
});

View file

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace App\Services\Trees;
use App\Entity\Base\StructuralDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Repository\StructuralDBElementRepository;
use App\Services\UserCacheKeyGenerator;
use Doctrine\ORM\EntityManagerInterface;
@ -52,11 +52,11 @@ class NodesListBuilder
* In difference to the Repository Function, the results here are cached.
*
* @param string $class_name The class name of the entity you want to retrieve.
* @param StructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root
* @param AbstractStructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root
*
* @return StructuralDBElement[] A flattened list containing the tree elements.
* @return AbstractStructuralDBElement[] A flattened list containing the tree elements.
*/
public function typeToNodesList(string $class_name, ?StructuralDBElement $parent = null): array
public function typeToNodesList(string $class_name, ?AbstractStructuralDBElement $parent = null): array
{
$parent_id = null !== $parent ? $parent->getID() : '0';
// Backslashes are not allowed in cache keys

View file

@ -24,9 +24,9 @@ declare(strict_types=1);
namespace App\Services\Trees;
use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Helpers\Trees\TreeViewNode;
use App\Helpers\Trees\TreeViewNodeIterator;
use App\Repository\StructuralDBElementRepository;
@ -59,14 +59,14 @@ class TreeViewGenerator
* Gets a TreeView list for the entities of the given class.
*
* @param string $class The class for which the treeView should be generated
* @param StructuralDBElement|null $parent The root nodes in the tree should have this element as parent (use null, if you want to get all entities)
* @param AbstractStructuralDBElement|null $parent The root nodes in the tree should have this element as parent (use null, if you want to get all entities)
* @param string $href_type The link type that will be generated for the hyperlink section of each node (see EntityURLGenerator for possible values).
* Set to empty string, to disable href field.
* @param DBElement|null $selectedElement The element that should be selected. If set to null, no element will be selected.
* @param AbstractDBElement|null $selectedElement The element that should be selected. If set to null, no element will be selected.
*
* @return TreeViewNode[] An array of TreeViewNode[] elements of the root elements.
*/
public function getTreeView(string $class, ?StructuralDBElement $parent = null, string $href_type = 'list_parts', ?DBElement $selectedElement = null): array
public function getTreeView(string $class, ?AbstractStructuralDBElement $parent = null, string $href_type = 'list_parts', ?AbstractDBElement $selectedElement = null): array
{
$head = [];
@ -115,13 +115,13 @@ class TreeViewGenerator
* The treeview is generic, that means the href are null and ID values are set.
*
* @param string $class The class for which the tree should be generated
* @param StructuralDBElement|null $parent The parent the root elements should have.
* @param AbstractStructuralDBElement|null $parent The parent the root elements should have.
*
* @return TreeViewNode[]
*/
public function getGenericTree(string $class, ?StructuralDBElement $parent = null): array
public function getGenericTree(string $class, ?AbstractStructuralDBElement $parent = null): array
{
if (! is_a($class, NamedDBElement::class, true)) {
if (! is_a($class, AbstractNamedDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
}
if (null !== $parent && ! is_a($parent, $class)) {