mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-31 23:40:20 +02:00
Added an PHP CS fixer config file and applied it to files.
We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
parent
89258bc102
commit
e557bdedd5
210 changed files with 2099 additions and 2742 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
|
@ -17,19 +17,13 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Services\Attachments;
|
||||
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\Attachments\AttachmentManager;
|
||||
|
||||
/**
|
||||
* @package App\Services\Attachments
|
||||
*/
|
||||
class PartPreviewGenerator
|
||||
{
|
||||
protected $attachmentHelper;
|
||||
|
@ -42,11 +36,13 @@ class PartPreviewGenerator
|
|||
/**
|
||||
* Returns a list of attachments that can be used for previewing the part ordered by priority.
|
||||
* The priority is: Part MasterAttachment -> Footprint MasterAttachment -> Category MasterAttachment
|
||||
* -> Storelocation Attachment -> MeasurementUnit Attachment -> ManufacturerAttachment
|
||||
* -> Storelocation Attachment -> MeasurementUnit Attachment -> ManufacturerAttachment.
|
||||
*
|
||||
* @param Part $part The part for which the attachments should be determined.
|
||||
*
|
||||
* @return Attachment[]
|
||||
*/
|
||||
public function getPreviewAttachments(Part $part) : array
|
||||
public function getPreviewAttachments(Part $part): array
|
||||
{
|
||||
$list = [];
|
||||
|
||||
|
@ -56,14 +52,14 @@ class PartPreviewGenerator
|
|||
$list[] = $attachment;
|
||||
}
|
||||
|
||||
if ($part->getFootprint() !== null) {
|
||||
if (null !== $part->getFootprint()) {
|
||||
$attachment = $part->getFootprint()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
if ($part->getCategory() !== null) {
|
||||
if (null !== $part->getCategory()) {
|
||||
$attachment = $part->getCategory()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
|
@ -71,7 +67,7 @@ class PartPreviewGenerator
|
|||
}
|
||||
|
||||
foreach ($part->getPartLots() as $lot) {
|
||||
if ($lot->getStorageLocation() !== null) {
|
||||
if (null !== $lot->getStorageLocation()) {
|
||||
$attachment = $lot->getStorageLocation()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
|
@ -79,14 +75,14 @@ class PartPreviewGenerator
|
|||
}
|
||||
}
|
||||
|
||||
if ($part->getPartUnit() !== null) {
|
||||
if (null !== $part->getPartUnit()) {
|
||||
$attachment = $part->getPartUnit()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
if ($part->getManufacturer() !== null) {
|
||||
if (null !== $part->getManufacturer()) {
|
||||
$attachment = $part->getManufacturer()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
$list[] = $attachment;
|
||||
|
@ -99,10 +95,12 @@ class PartPreviewGenerator
|
|||
/**
|
||||
* Determines what attachment should be used for previewing a part (especially in part table).
|
||||
* The returned attachment is guaranteed to be existing and be a picture.
|
||||
*
|
||||
* @param Part $part The part for which the attachment should be determined
|
||||
*
|
||||
* @return Attachment|null
|
||||
*/
|
||||
public function getTablePreviewAttachment(Part $part) : ?Attachment
|
||||
public function getTablePreviewAttachment(Part $part): ?Attachment
|
||||
{
|
||||
//First of all we check if the master attachment of the part is set (and a picture)
|
||||
$attachment = $part->getMasterPictureAttachment();
|
||||
|
@ -111,7 +109,7 @@ class PartPreviewGenerator
|
|||
}
|
||||
|
||||
//Otherwise check if the part has a footprint with a valid masterattachment
|
||||
if ($part->getFootprint() !== null) {
|
||||
if (null !== $part->getFootprint()) {
|
||||
$attachment = $part->getFootprint()->getMasterPictureAttachment();
|
||||
if ($this->isAttachmentValidPicture($attachment)) {
|
||||
return $attachment;
|
||||
|
@ -124,13 +122,15 @@ class PartPreviewGenerator
|
|||
|
||||
/**
|
||||
* Checks if a attachment is exising and a valid picture.
|
||||
*
|
||||
* @param Attachment|null $attachment The attachment that should be checked.
|
||||
*
|
||||
* @return bool True if the attachment is valid.
|
||||
*/
|
||||
protected function isAttachmentValidPicture(?Attachment $attachment) : bool
|
||||
protected function isAttachmentValidPicture(?Attachment $attachment): bool
|
||||
{
|
||||
return $attachment !== null
|
||||
return null !== $attachment
|
||||
&& $attachment->isPicture()
|
||||
&& $this->attachmentHelper->isFileExisting($attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue