Fixed some inspection issues.

This commit is contained in:
Jan Böhmer 2019-08-20 18:39:57 +02:00
parent 8e23629dc0
commit 1629f31fed
31 changed files with 187 additions and 211 deletions

View file

@ -27,7 +27,6 @@ use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Intl\Exception\NotImplementedException;
/**
* Class Attachment.
@ -114,7 +113,7 @@ abstract class Attachment extends NamedDBElement
/**
* Get the element, associated with this Attachement (for example a "Part" object).
*
* @return DBElement The associated Element.
* @return AttachmentContainingDBElement The associated Element.
*/
public function getElement(): ?AttachmentContainingDBElement
{
@ -260,8 +259,8 @@ abstract class Attachment extends NamedDBElement
}
if ($path_required) {
return (bool) filter_var($string, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED);
} else {
return (bool) filter_var($string, FILTER_VALIDATE_URL);
}
return (bool) filter_var($string, FILTER_VALIDATE_URL);
}
}

View file

@ -56,7 +56,6 @@ use App\Entity\Base\NamedDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Exception;
/**
@ -103,11 +102,11 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
/**
* Get all attachements of this element / Get the element's attachements with a specific type.
*
* @param int $type_id * if NULL, all attachements of this element will be returned
* * if this is a number > 0, only attachements with this type ID will be returned
* @param int $type_id * if NULL, all attachements of this element will be returned
* * if this is a number > 0, only attachements with this type ID will be returned
* @param bool $only_table_attachements if true, only attachements with "show_in_table == true"
*
* @return Attachment[] the attachements as a one-dimensional array of Attachement objects
* @return Collection|Attachment[] the attachements as a one-dimensional array of Attachement objects
*
* @throws Exception if there was an error
*/

View file

@ -53,7 +53,6 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Base\StructuralDBElement;
use App\Validator\Constraints\NoneOfItsChildren;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -86,7 +85,7 @@ class AttachmentType extends StructuralDBElement
/**
* Get all attachements ("Attachement" objects) with this type.
*
* @return Attachment[] all attachements with this type, as a one-dimensional array of Attachement-objects
* @return Collection|Attachment[] all attachements with this type, as a one-dimensional array of Attachement-objects
* (sorted by their names)
*/
public function getAttachementsForType(): Collection

View file

@ -52,7 +52,6 @@ declare(strict_types=1);
namespace App\Entity\Base;
use App\Entity\Base\StructuralDBElement;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -67,39 +66,39 @@ abstract class Company extends StructuralDBElement
* @var string The address of the company
* @ORM\Column(type="string")
*/
protected $address = "";
protected $address = '';
/**
* @var string The phone number of the company
* @ORM\Column(type="string")
*/
protected $phone_number = "";
protected $phone_number = '';
/**
* @var string The fax number of the company
* @ORM\Column(type="string")
*/
protected $fax_number = "";
protected $fax_number = '';
/**
* @var string The email address of the company
* @ORM\Column(type="string")
* @Assert\Email()
*/
protected $email_address = "";
protected $email_address = '';
/**
* @var string The website of the company
* @ORM\Column(type="string")
* @Assert\Url()
*/
protected $website = "";
protected $website = '';
/**
* @var string
* @ORM\Column(type="string")
*/
protected $auto_product_url = "";
protected $auto_product_url = '';
/********************************************************************************
*

View file

@ -55,10 +55,8 @@ namespace App\Entity\Base;
use App\Entity\Attachments\AttachmentContainingDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use App\Validator\Constraints\NoneOfItsChildren;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
/**
@ -102,7 +100,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* @ORM\Column(type="text")
* @Groups({"simple", "extended", "full"})
*/
protected $comment = "";
protected $comment = '';
/**
* @var int
@ -132,6 +130,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
public function __construct()
{
parent::__construct();
$this->children = new ArrayCollection();
}
@ -154,16 +153,16 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$class_name = \get_class($this);
//Check if both elements compared, are from the same type:
if ($class_name != \get_class($another_element)) {
if ($class_name !== \get_class($another_element)) {
throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!');
}
if (null == $this->getParent()) { // this is the root node
if (null === $this->getParent()) { // this is the root node
return false;
}
//If this' parents element, is $another_element, then we are finished
return ($this->parent->getID() == $another_element->getID())
return ($this->parent->getID() === $another_element->getID())
|| $this->parent->isChildOf($another_element); //Otherwise, check recursivley
}
@ -247,7 +246,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$overflow = 20; //We only allow 20 levels depth
while (null != $element->parent && $overflow >= 0) {
while (null !== $element->parent && $overflow >= 0) {
$element = $element->parent;
$this->full_path_strings[] = $element->getName();
//Decrement to prevent mem overflow.

View file

@ -83,13 +83,13 @@ class Category extends PartsContainingDBElement
* @var string
* @ORM\Column(type="text")
*/
protected $partname_hint = "";
protected $partname_hint = '';
/**
* @var string
* @ORM\Column(type="text")
*/
protected $partname_regex = "";
protected $partname_regex = '';
/**
* @var bool
@ -119,13 +119,13 @@ class Category extends PartsContainingDBElement
* @var string
* @ORM\Column(type="text")
*/
protected $default_description = "";
protected $default_description = '';
/**
* @var string
* @ORM\Column(type="text")
*/
protected $default_comment = "";
protected $default_comment = '';
/**
* Returns the ID as an string, defined by the element class.

View file

@ -128,73 +128,14 @@ class Footprint extends PartsContainingDBElement
/**
* Get the filename of the 3d model (absolute path from filesystem root).
*
* @param bool $absolute If set to true, then the absolute filename (from system root) is returned.
* If set to false, then the path relative to Part-DB folder is returned.
*
* @return string * the absolute path to the model (from filesystem root), as a UNIX path (with slashes)
* * an empty string if there is no model
*/
public function get3dFilename(bool $absolute = true): string
public function get3dFilename(): string
{
if (true === $absolute) {
//TODO
throw new \Exception('Not Implemented yet...');
//return str_replace('%BASE%', BASE, $this->db_data['filename_3d']);
}
return $this->filename_3d;
}
/**
* Check if the filename of this footprint is valid (picture exists).
*
* This method is used to get all footprints with broken filename
* (Footprint::get_broken_filename_footprints()).
*
* An empty filename is a valid filename.
*
* @return bool * true if file exists or filename is empty
* * false if there is no file with this filename
*/
public function isFilenameValid(): bool
{
if (empty($this->getFilename())) {
return true;
}
return file_exists($this->getFilename());
}
/**
* Check if the filename of this 3d footprint is valid (model exists and have ).
*
* This method is used to get all footprints with broken 3d filename
* (Footprint::get_broken_3d_filename_footprints()).
*
* An empty filename is a valid filename.
*
* @return bool * true if file exists or filename is empty
* * false if there is no file with this filename
*/
public function is3dFilenameValid(): bool
{
if (empty($this->get3dFilename())) {
return true;
}
//Check if file is X3D-Model (these has .x3d extension)
if (false === strpos($this->get3dFilename(), '.x3d')) {
return false;
}
return file_exists($this->get3dFilename());
}
/*****************************************************************************
* Setters
****************************************************************************/
/********************************************************************************
*
* Setters
@ -203,25 +144,8 @@ class Footprint extends PartsContainingDBElement
/**
* Change the filename of this footprint.
*
* The filename won't be checked if it is valid.
* It's not really a Problem if there is no such file...
* (For this purpose we have the method Footprint::get_broken_filename_footprints())
*
* @param string $new_filename * the new filename (absolute path from filesystem root, as a UNIX path [only slashes!] !! )
* * see also lib.functions.php::to_unix_path()
*
* It's really important that you pass the whole (UNIX) path from filesystem root!
* If the file is located in the base directory of Part-DB, the base path
* will be automatically replaced with a placeholder before write it in the database.
* This way, the filenames are still correct if the installation directory
* of Part-DB is moved.
*
* The path-replacing will be done in Footprint::check_values_validity(), not here.
*
* @return Footprint
*
* @throws \Exception if there was an error
* @param string $new_filename The new file name
* @return Footprint
*/
public function setFilename(string $new_filename): self
{
@ -232,8 +156,9 @@ class Footprint extends PartsContainingDBElement
/**
* Change the 3d model filename of this footprint.
* @param string $new_filename The new filename
*
* @throws \Exception if there was an error
* @return Footprint
*/
public function set3dFilename(string $new_filename): self
{

View file

@ -33,7 +33,6 @@ namespace App\Entity\Parts;
use App\Entity\Base\PartsContainingDBElement;
use App\Entity\Base\StructuralDBElement;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
@ -127,7 +126,7 @@ class MeasurementUnit extends PartsContainingDBElement
*/
public function setIsInteger(bool $isInteger): MeasurementUnit
{
$this->isInteger = $isInteger;
$this->is_integer = $isInteger;
return $this;
}
@ -145,7 +144,7 @@ class MeasurementUnit extends PartsContainingDBElement
*/
public function setUseSIPrefix(bool $usesSIPrefixes): MeasurementUnit
{
$this->useSIPrefixes = $usesSIPrefixes;
$this->use_si_prefix = $usesSIPrefixes;
return $this;
}
}

View file

@ -71,7 +71,6 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -169,7 +168,7 @@ class Part extends AttachmentContainingDBElement
*
* @ColumnSecurity(prefix="name")
*/
protected $name = '';
protected $name;
/**
* @var string
@ -303,12 +302,18 @@ class Part extends AttachmentContainingDBElement
/**
* Get the count of parts which must be in stock at least.
* If a integer-based part unit is selected, the value will be rounded to integers
*
* @return int count of parts which must be in stock at least
* @return float count of parts which must be in stock at least
*/
public function getMinAmount(): float
{
return $this->minamount;
if ($this->useFloatAmount()) {
return $this->minamount;
}
return round($this->minamount);
}
/**
@ -476,7 +481,7 @@ class Part extends AttachmentContainingDBElement
*
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
*
* @return Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
* @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
* (empty array if there are no ones)
* * the array is sorted by the suppliers names / minimum order quantity
*
@ -638,7 +643,7 @@ class Part extends AttachmentContainingDBElement
/**
* Gets the measurement unit in which the part's amount should be measured.
* Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers.
* @return ?MeasurementUnit
* @return MeasurementUnit|null
*/
public function getPartUnit(): ?MeasurementUnit
{
@ -648,7 +653,7 @@ class Part extends AttachmentContainingDBElement
/**
* Sets the measurement unit in which the part's amount should be measured.
* Set to null, if the part should be measured in quantities.
* @param ?MeasurementUnit $partUnit
* @param MeasurementUnit|null $partUnit
* @return Part
*/
public function setPartUnit(?MeasurementUnit $partUnit): Part
@ -762,7 +767,7 @@ class Part extends AttachmentContainingDBElement
* Set the minimum amount of parts that have to be instock.
* See getPartUnit() for the associated unit.
*
* @param int $new_mininstock the new count of parts which should be in stock at least
* @param int $new_minamount the new count of parts which should be in stock at least
*
* @return self
*/

View file

@ -33,7 +33,6 @@ namespace App\Entity\Parts;
use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\TimestampTrait;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
@ -56,13 +55,13 @@ class PartLot extends DBElement
* @var string A short description about this lot, shown in table
* @ORM\Column(type="text")
*/
protected $description = "";
protected $description = '';
/**
* @var string A comment stored with this lot.
* @ORM\Column(type="text")
*/
protected $comment = "";
protected $comment = '';
/**
* @var ?\DateTime Set a time until when the lot must be used.
@ -126,7 +125,7 @@ class PartLot extends DBElement
*/
public function isExpired(): ?bool
{
if ($this->expiration_date == null) {
if ($this->expiration_date === null) {
return null;
}

View file

@ -61,9 +61,7 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Base\PartsContainingDBElement;
use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use Doctrine\ORM\Mapping as ORM;
/**

View file

@ -100,7 +100,7 @@ class Currency extends StructuralDBElement
{
$tmp = $this->getExchangeRate();
if ($tmp == null) {
if ($tmp === null) {
return null;
}

View file

@ -237,7 +237,7 @@ class Orderdetail extends DBElement
public function getPrice(int $quantity = 1, $multiplier = null) : ?float
{
if (($quantity == 0) && ($multiplier === null)) {
if (($quantity === 0) && ($multiplier === null)) {
return 0.0;
}
@ -258,7 +258,7 @@ class Orderdetail extends DBElement
$correct_pricedetails = $pricedetails;
}
if ($correct_pricedetails == null) {
if ($correct_pricedetails === null) {
return null;
}
@ -276,22 +276,21 @@ class Orderdetail extends DBElement
*********************************************************************************/
/**
* Set the supplier ID.
*
* @param int $new_supplier_id the ID of the new supplier
* Sets the new supplier associated with this orderdetail.
* @param Supplier $new_supplier
* @return Orderdetail
*/
public function setSupplierId(int $new_supplier_id): self
public function setSupplier(Supplier $new_supplier) : Orderdetail
{
throw new \Exception('Not implemented yet!');
//TODO;
$this->supplier = $new_supplier;
return $this;
}
/**
* Set the supplier part-nr.
*
* @param string $new_supplierpartnr the new supplier-part-nr
* @return Orderdetail
* @return Orderdetail
*/
public function setSupplierpartnr(string $new_supplierpartnr): self
{
@ -302,8 +301,9 @@ class Orderdetail extends DBElement
/**
* Set if the part is obsolete at the supplier of that orderdetails.
*
* @param bool $new_obsolete true means that this part is obsolete
* @return Orderdetail
* @return Orderdetail
*/
public function setObsolete(bool $new_obsolete): self
{
@ -315,8 +315,9 @@ class Orderdetail extends DBElement
/**
* Sets the custom product supplier URL for this order detail.
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
*
* @param $new_url string The new URL for the supplier URL.
* @return Orderdetail
* @return Orderdetail
*/
public function setSupplierProductUrl(string $new_url)
{

View file

@ -220,6 +220,7 @@ class Pricedetail extends DBElement
public function setCurrency(?Currency $currency): Pricedetail
{
$this->currency = $currency;
return $this;
}
/**

View file

@ -91,7 +91,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank
*/
protected $name = "";
protected $name = '';
/**
* //@ORM\Column(type="json").