mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 19:58:53 +02:00
Fixed some inspection issues.
This commit is contained in:
parent
eef26f7ae6
commit
639829f5c5
97 changed files with 305 additions and 185 deletions
|
@ -23,6 +23,7 @@ namespace App\Repository;
|
|||
use App\Entity\Base\AbstractPartsContainingDBElement;
|
||||
use App\Entity\Base\PartsContainingRepositoryInterface;
|
||||
use App\Entity\Parts\Part;
|
||||
use InvalidArgumentException;
|
||||
|
||||
abstract class AbstractPartsContainingRepository extends StructuralDBElementRepository implements PartsContainingRepositoryInterface
|
||||
{
|
||||
|
@ -46,7 +47,7 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
|
|||
protected function getPartsByField(object $element, array $order_by, string $field_name): array
|
||||
{
|
||||
if (!$element instanceof AbstractPartsContainingDBElement) {
|
||||
throw new \InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
|
||||
throw new InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
|
||||
}
|
||||
|
||||
$repo = $this->getEntityManager()->getRepository(Part::class);
|
||||
|
@ -57,7 +58,7 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
|
|||
protected function getPartsCountByField(object $element, string $field_name): int
|
||||
{
|
||||
if (!$element instanceof AbstractPartsContainingDBElement) {
|
||||
throw new \InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
|
||||
throw new InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
|
||||
}
|
||||
|
||||
$repo = $this->getEntityManager()->getRepository(Part::class);
|
||||
|
|
|
@ -23,6 +23,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Repository;
|
||||
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
|
||||
class AttachmentRepository extends DBElementRepository
|
||||
{
|
||||
/**
|
||||
|
@ -42,8 +45,8 @@ class AttachmentRepository extends DBElementRepository
|
|||
/**
|
||||
* Gets the count of all external attachments (attachments only containing an URL).
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getExternalAttachments(): int
|
||||
{
|
||||
|
@ -61,8 +64,8 @@ class AttachmentRepository extends DBElementRepository
|
|||
/**
|
||||
* Gets the count of all attachments where an user uploaded an file.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getUserUploadedAttachments(): int
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Repository;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use ReflectionClass;
|
||||
|
||||
class DBElementRepository extends EntityRepository
|
||||
{
|
||||
|
@ -68,7 +69,7 @@ class DBElementRepository extends EntityRepository
|
|||
|
||||
protected function setField(AbstractDBElement $element, string $field, int $new_value): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($element, $new_value);
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Repository;
|
|||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class LabelProfileRepository extends NamedDBElementRepository
|
||||
{
|
||||
|
@ -36,7 +37,7 @@ class LabelProfileRepository extends NamedDBElementRepository
|
|||
public function getDropdownProfiles(string $type): array
|
||||
{
|
||||
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) {
|
||||
throw new \InvalidArgumentException('Invalid supported_element type given.');
|
||||
throw new InvalidArgumentException('Invalid supported_element type given.');
|
||||
}
|
||||
|
||||
return $this->findBy([
|
||||
|
@ -85,7 +86,7 @@ class LabelProfileRepository extends NamedDBElementRepository
|
|||
public function findForSupportedElement(string $type, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) {
|
||||
throw new \InvalidArgumentException('Invalid supported_element type given.');
|
||||
throw new InvalidArgumentException('Invalid supported_element type given.');
|
||||
}
|
||||
|
||||
return $this->findBy(['options.supported_element' => $type], $order_by);
|
||||
|
|
|
@ -49,6 +49,11 @@ use App\Entity\LogSystem\ElementCreatedLogEntry;
|
|||
use App\Entity\LogSystem\ElementDeletedLogEntry;
|
||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||
use App\Entity\UserSystem\User;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\OptimisticLockException;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Doctrine\ORM\TransactionRequiredException;
|
||||
use RuntimeException;
|
||||
|
||||
class LogEntryRepository extends DBElementRepository
|
||||
{
|
||||
|
@ -108,7 +113,7 @@ class LogEntryRepository extends DBElementRepository
|
|||
$results = $query->execute();
|
||||
|
||||
if (empty($results)) {
|
||||
throw new \RuntimeException('No undelete data could be found for this element');
|
||||
throw new RuntimeException('No undelete data could be found for this element');
|
||||
}
|
||||
|
||||
return $results[0];
|
||||
|
@ -118,11 +123,11 @@ class LogEntryRepository extends DBElementRepository
|
|||
* Gets all log entries that are related to time travelling.
|
||||
*
|
||||
* @param AbstractDBElement $element The element for which the time travel data should be retrieved
|
||||
* @param \DateTime $until Back to which timestamp should the data be get (including the timestamp)
|
||||
* @param DateTime $until Back to which timestamp should the data be get (including the timestamp)
|
||||
*
|
||||
* @return AbstractLogEntry[]
|
||||
*/
|
||||
public function getTimetravelDataForElement(AbstractDBElement $element, \DateTime $until): array
|
||||
public function getTimetravelDataForElement(AbstractDBElement $element, DateTime $until): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('log');
|
||||
$qb->select('log')
|
||||
|
@ -150,7 +155,7 @@ class LogEntryRepository extends DBElementRepository
|
|||
*
|
||||
* @return bool True if the element existed at the given timestamp
|
||||
*/
|
||||
public function getElementExistedAtTimestamp(AbstractDBElement $element, \DateTime $timestamp): bool
|
||||
public function getElementExistedAtTimestamp(AbstractDBElement $element, DateTime $timestamp): bool
|
||||
{
|
||||
$qb = $this->createQueryBuilder('log');
|
||||
$qb->select('count(log)')
|
||||
|
@ -190,9 +195,9 @@ class LogEntryRepository extends DBElementRepository
|
|||
* @return AbstractDBElement|null returns the associated DBElement or null if the log either has no target or the element
|
||||
* was deleted from DB
|
||||
*
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
* @throws ORMException
|
||||
* @throws OptimisticLockException
|
||||
* @throws TransactionRequiredException
|
||||
*/
|
||||
public function getTargetElement(AbstractLogEntry $logEntry): ?AbstractDBElement
|
||||
{
|
||||
|
|
|
@ -43,6 +43,8 @@ declare(strict_types=1);
|
|||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Parts\PartLot;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
class PartRepository extends NamedDBElementRepository
|
||||
|
@ -50,8 +52,8 @@ class PartRepository extends NamedDBElementRepository
|
|||
/**
|
||||
* Gets the summed up instock of all parts (only parts without an measurent unit).
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getPartsInstockSum(): float
|
||||
{
|
||||
|
@ -69,8 +71,8 @@ class PartRepository extends NamedDBElementRepository
|
|||
/**
|
||||
* Gets the number of parts that has price informations.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getPartsCountWithPrice(): int
|
||||
{
|
||||
|
|
|
@ -22,13 +22,14 @@ namespace App\Repository\Parts;
|
|||
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class CategoryRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof Category) {
|
||||
throw new \InvalidArgumentException('$element must be an Category!');
|
||||
throw new InvalidArgumentException('$element must be an Category!');
|
||||
}
|
||||
|
||||
return $this->getPartsByField($element, $order_by, 'category');
|
||||
|
@ -37,7 +38,7 @@ class CategoryRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof Category) {
|
||||
throw new \InvalidArgumentException('$element must be an Category!');
|
||||
throw new InvalidArgumentException('$element must be an Category!');
|
||||
}
|
||||
|
||||
return $this->getPartsCountByField($element, 'category');
|
||||
|
|
|
@ -9,6 +9,7 @@ use App\Entity\Devices\Device;
|
|||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class DeviceRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ class DeviceRepository extends AbstractPartsContainingRepository
|
|||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof Device) {
|
||||
throw new \InvalidArgumentException('$element must be an Device!');
|
||||
throw new InvalidArgumentException('$element must be an Device!');
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +28,7 @@ class DeviceRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof Device) {
|
||||
throw new \InvalidArgumentException('$element must be an Device!');
|
||||
throw new InvalidArgumentException('$element must be an Device!');
|
||||
}
|
||||
|
||||
//TODO: Change this later, when properly implemented devices
|
||||
|
|
|
@ -22,13 +22,14 @@ namespace App\Repository\Parts;
|
|||
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class FootprintRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof Footprint) {
|
||||
throw new \InvalidArgumentException('$element must be an Footprint!');
|
||||
throw new InvalidArgumentException('$element must be an Footprint!');
|
||||
}
|
||||
|
||||
return $this->getPartsByField($element, $order_by, 'footprint');
|
||||
|
@ -37,7 +38,7 @@ class FootprintRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof Footprint) {
|
||||
throw new \InvalidArgumentException('$element must be an Footprint!');
|
||||
throw new InvalidArgumentException('$element must be an Footprint!');
|
||||
}
|
||||
|
||||
return $this->getPartsCountByField($element, 'footprint');
|
||||
|
|
|
@ -22,13 +22,14 @@ namespace App\Repository\Parts;
|
|||
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ManufacturerRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof Manufacturer) {
|
||||
throw new \InvalidArgumentException('$element must be an Manufacturer!');
|
||||
throw new InvalidArgumentException('$element must be an Manufacturer!');
|
||||
}
|
||||
|
||||
return $this->getPartsByField($element, $order_by, 'manufacturer');
|
||||
|
@ -37,7 +38,7 @@ class ManufacturerRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof Manufacturer) {
|
||||
throw new \InvalidArgumentException('$element must be an Manufacturer!');
|
||||
throw new InvalidArgumentException('$element must be an Manufacturer!');
|
||||
}
|
||||
|
||||
return $this->getPartsCountByField($element, 'manufacturer');
|
||||
|
|
|
@ -22,13 +22,14 @@ namespace App\Repository\Parts;
|
|||
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class MeasurementUnitRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof MeasurementUnit) {
|
||||
throw new \InvalidArgumentException('$element must be an MeasurementUnit!');
|
||||
throw new InvalidArgumentException('$element must be an MeasurementUnit!');
|
||||
}
|
||||
|
||||
return $this->getPartsByField($element, $order_by, 'partUnit');
|
||||
|
@ -37,7 +38,7 @@ class MeasurementUnitRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof MeasurementUnit) {
|
||||
throw new \InvalidArgumentException('$element must be an MeasurementUnit!');
|
||||
throw new InvalidArgumentException('$element must be an MeasurementUnit!');
|
||||
}
|
||||
|
||||
return $this->getPartsCountByField($element, 'partUnit');
|
||||
|
|
|
@ -24,6 +24,7 @@ use App\Entity\Parts\Part;
|
|||
use App\Entity\Parts\Storelocation;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class StorelocationRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
|
@ -33,7 +34,7 @@ class StorelocationRepository extends AbstractPartsContainingRepository
|
|||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof Storelocation) {
|
||||
throw new \InvalidArgumentException('$element must be an Storelocation!');
|
||||
throw new InvalidArgumentException('$element must be an Storelocation!');
|
||||
}
|
||||
|
||||
$qb = new QueryBuilder($this->getEntityManager());
|
||||
|
@ -54,7 +55,7 @@ class StorelocationRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof Storelocation) {
|
||||
throw new \InvalidArgumentException('$element must be an Storelocation!');
|
||||
throw new InvalidArgumentException('$element must be an Storelocation!');
|
||||
}
|
||||
|
||||
$qb = new QueryBuilder($this->getEntityManager());
|
||||
|
|
|
@ -24,13 +24,14 @@ use App\Entity\Parts\Part;
|
|||
use App\Entity\Parts\Supplier;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class SupplierRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
{
|
||||
if (!$element instanceof Supplier) {
|
||||
throw new \InvalidArgumentException('$element must be an Supplier!');
|
||||
throw new InvalidArgumentException('$element must be an Supplier!');
|
||||
}
|
||||
|
||||
$qb = new QueryBuilder($this->getEntityManager());
|
||||
|
@ -51,7 +52,7 @@ class SupplierRepository extends AbstractPartsContainingRepository
|
|||
public function getPartsCount(object $element): int
|
||||
{
|
||||
if (!$element instanceof Supplier) {
|
||||
throw new \InvalidArgumentException('$element must be an Supplier!');
|
||||
throw new InvalidArgumentException('$element must be an Supplier!');
|
||||
}
|
||||
|
||||
$qb = new QueryBuilder($this->getEntityManager());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue