.
*/
namespace App\Services\LabelSystem\Barcodes;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
final class BarcodeExampleElementsGenerator
{
public function getElement(string $type): object
{
switch ($type) {
case 'part':
return $this->getExamplePart();
case 'part_lot':
return $this->getExamplePartLot();
case 'storelocation':
return $this->getStorelocation();
default:
throw new \InvalidArgumentException('Unknown $type.');
}
}
public function getExamplePart(): Part
{
$part = new Part();
$part->setName('Example Part');
$part->setDescription('Part description');
$part->setComment('Part comment');
$part->setCategory($this->getStructuralData(Category::class));
$part->setFootprint($this->getStructuralData(Footprint::class));
$part->setManufacturer($this->getStructuralData(Manufacturer::class));
$part->setMass(123.4);
$part->setManufacturerProductNumber('CUSTOM MPN');
$part->setTags('Tag1, Tag2, Tag3');
$part->setManufacturingStatus('active');
$part->updateTimestamps();
$part->setFavorite(true);
$part->setMinAmount(100);
$part->setNeedsReview(true);
return $part;
}
public function getExamplePartLot(): PartLot
{
$lot = new PartLot();
$lot->setPart($this->getExamplePart());
$lot->setDescription('Example Lot');
$lot->setComment('Lot comment');
$lot->setExpirationDate(new \DateTime('+1 days'));
$lot->setStorageLocation($this->getStructuralData(Storelocation::class));
$lot->setAmount(123);
return $lot;
}
private function getStorelocation(): Storelocation
{
$storelocation = new Storelocation();
$storelocation->setName('Location 1');
$storelocation->setComment('Example comment');
$storelocation->updateTimestamps();
$parent = new Storelocation();
$parent->setName('Parent');
$storelocation->setParent($parent);
return $storelocation;
}
private function getStructuralData(string $class): AbstractStructuralDBElement
{
if (! is_a($class, AbstractStructuralDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
}
/** @var AbstractStructuralDBElement $parent */
$parent = new $class();
$parent->setName('Example');
/** @var AbstractStructuralDBElement $child */
$child = new $class();
$child->setName((new \ReflectionClass($class))->getShortName());
$child->setParent($parent);
return $child;
}
}