Added declare strict types to all files

This commit is contained in:
Jan Böhmer 2023-06-11 18:59:07 +02:00
parent bea90a7d94
commit 6a2ff9d153
196 changed files with 685 additions and 360 deletions

View file

@ -182,7 +182,7 @@ abstract class Attachment extends AbstractNamedDBElement
public function isExternal(): bool
{
//When path is empty, this attachment can not be external
if (empty($this->path)) {
if ($this->path === '') {
return false;
}
@ -236,7 +236,7 @@ abstract class Attachment extends AbstractNamedDBElement
return null;
}
if (!empty($this->original_filename)) {
if ($this->original_filename !== null && $this->original_filename !== '') {
return strtolower(pathinfo($this->original_filename, PATHINFO_EXTENSION));
}
@ -302,7 +302,7 @@ abstract class Attachment extends AbstractNamedDBElement
}
//If we have a stored original filename, then use it
if (!empty($this->original_filename)) {
if ($this->original_filename !== null && $this->original_filename !== '') {
return $this->original_filename;
}
@ -411,7 +411,7 @@ abstract class Attachment extends AbstractNamedDBElement
public function setURL(?string $url): self
{
//Only set if the URL is not empty
if (!empty($url)) {
if ($url !== null && $url !== '') {
if (str_contains($url, '%BASE%') || str_contains($url, '%MEDIA%')) {
throw new InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\Base;
use App\Entity\Parts\Part;

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\Contracts;
interface LogWithNewDataInterface
@ -38,4 +40,4 @@ interface LogWithNewDataInterface
* @return $this
*/
public function setNewData(array $new_data): self;
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\LogSystem;
use App\Entity\Parts\PartLot;
@ -64,7 +66,7 @@ class PartStockChangedLogEntry extends AbstractLogEntry
'n' => $new_stock,
'p' => $new_total_part_instock,
]);
if (!empty($comment)) {
if ($comment !== '') {
$this->extra['c'] = mb_strimwidth($comment, 0, self::COMMENT_MAX_LENGTH, '...');
}
@ -201,4 +203,4 @@ class PartStockChangedLogEntry extends AbstractLogEntry
default => throw new \InvalidArgumentException('Invalid short type: '.$short_type),
};
}
}
}

View file

@ -394,7 +394,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement
protected function formatWithUnit(float $value, string $format = '%g'): string
{
$str = sprintf($format, $value);
if (!empty($this->unit)) {
if ($this->unit !== '') {
return $str.' '.$this->unit;
}

View file

@ -147,7 +147,7 @@ class Part extends AttachmentContainingDBElement
//Ensure that the part name fullfills the regex of the category
if ($this->category instanceof Category) {
$regex = $this->category->getPartnameRegex();
if (!empty($regex) && !preg_match($regex, $this->name)) {
if ($regex !== '' && !preg_match($regex, $this->name)) {
$context->buildViolation('part.name.must_match_category_regex')
->atPath('name')
->setParameter('%regex%', $regex)

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Entity\Parts\PartTraits;
use App\Entity\ProjectSystem\Project;
@ -81,4 +83,4 @@ trait ProjectTrait
return $projects;
}
}
}

View file

@ -242,7 +242,7 @@ class ProjectBOMEntry extends AbstractDBElement
}
//Check that the number of mountnames is the same as the (rounded) quantity
if (!empty($this->mountnames) && count($uniq_mountnames) !== (int) round ($this->quantity)) {
if ($this->mountnames !== '' && count($uniq_mountnames) !== (int) round ($this->quantity)) {
$context->buildViolation('project.bom_entry.mountnames_quantity_mismatch')
->atPath('mountnames')
->addViolation();

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\UserSystem;
use Doctrine\DBAL\Types\Types;
@ -228,4 +230,4 @@ final class PermissionData implements \JsonSerializable
return $this;
}
}
}

View file

@ -500,7 +500,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
{
$tmp = $this->getFirstName();
//Don't add a space, if the name has only one part (it would look strange)
if (!empty($this->getFirstName()) && !empty($this->getLastName())) {
if ($this->getFirstName() !== null && $this->getFirstName() !== '' && ($this->getLastName() !== null && $this->getLastName() !== '')) {
$tmp .= ' ';
}
$tmp .= $this->getLastName();

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -17,7 +20,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\UserSystem;
use Doctrine\DBAL\Types\Types;
@ -89,4 +91,4 @@ class WebauthnKey extends BasePublicKeyCredentialSource
$registration->getOtherUI()
);
}
}
}