Applied rector suggestions

This commit is contained in:
Jan Böhmer 2024-06-22 00:31:43 +02:00
parent 4106bcef5f
commit 20f32c7f12
170 changed files with 808 additions and 761 deletions

View file

@ -72,22 +72,20 @@ class AttachmentTest extends TestCase
$this->assertEmpty($attachment->getFilename());
}
public function subClassesDataProvider(): array
public function subClassesDataProvider(): \Iterator
{
return [
[AttachmentTypeAttachment::class, AttachmentType::class],
[CategoryAttachment::class, Category::class],
[CurrencyAttachment::class, Currency::class],
[ProjectAttachment::class, Project::class],
[FootprintAttachment::class, Footprint::class],
[GroupAttachment::class, Group::class],
[ManufacturerAttachment::class, Manufacturer::class],
[MeasurementUnitAttachment::class, MeasurementUnit::class],
[PartAttachment::class, Part::class],
[StorageLocationAttachment::class, StorageLocation::class],
[SupplierAttachment::class, Supplier::class],
[UserAttachment::class, User::class],
];
yield [AttachmentTypeAttachment::class, AttachmentType::class];
yield [CategoryAttachment::class, Category::class];
yield [CurrencyAttachment::class, Currency::class];
yield [ProjectAttachment::class, Project::class];
yield [FootprintAttachment::class, Footprint::class];
yield [GroupAttachment::class, Group::class];
yield [ManufacturerAttachment::class, Manufacturer::class];
yield [MeasurementUnitAttachment::class, MeasurementUnit::class];
yield [PartAttachment::class, Part::class];
yield [StorageLocationAttachment::class, StorageLocation::class];
yield [SupplierAttachment::class, Supplier::class];
yield [UserAttachment::class, User::class];
}
/**
@ -117,27 +115,21 @@ class AttachmentTest extends TestCase
/** @var Attachment $attachment */
$attachment = new $attachment_class();
if (Project::class !== $allowed_class) {
$element = new Project();
} else {
$element = new Category();
}
$element = Project::class !== $allowed_class ? new Project() : new Category();
$attachment->setElement($element);
}
public function externalDataProvider(): array
public function externalDataProvider(): \Iterator
{
return [
['', false],
['%MEDIA%/foo/bar.txt', false],
['%BASE%/foo/bar.jpg', false],
['%FOOTPRINTS%/foo/bar.jpg', false],
['%FOOTPRINTS3D%/foo/bar.jpg', false],
['%SECURE%/test.txt', false],
['%test%/foo/bar.ghp', true],
['foo%MEDIA%/foo.jpg', true],
['foo%MEDIA%/%BASE%foo.jpg', true],
];
yield ['', false];
yield ['%MEDIA%/foo/bar.txt', false];
yield ['%BASE%/foo/bar.jpg', false];
yield ['%FOOTPRINTS%/foo/bar.jpg', false];
yield ['%FOOTPRINTS3D%/foo/bar.jpg', false];
yield ['%SECURE%/test.txt', false];
yield ['%test%/foo/bar.ghp', true];
yield ['foo%MEDIA%/foo.jpg', true];
yield ['foo%MEDIA%/%BASE%foo.jpg', true];
}
/**
@ -150,20 +142,18 @@ class AttachmentTest extends TestCase
$this->assertSame($expected, $attachment->isExternal());
}
public function extensionDataProvider(): array
public function extensionDataProvider(): \Iterator
{
return [
['%MEDIA%/foo/bar.txt', null, 'txt'],
['%MEDIA%/foo/bar.JPeg', null, 'jpeg'],
['%MEDIA%/foo/bar.JPeg', 'test.txt', 'txt'],
['%MEDIA%/foo/bar', null, ''],
['%MEDIA%/foo.bar', 'bar', ''],
['http://google.de', null, null],
['https://foo.bar', null, null],
['https://foo.bar/test.jpeg', null, null],
['test', null, null],
['test.txt', null, null],
];
yield ['%MEDIA%/foo/bar.txt', null, 'txt'];
yield ['%MEDIA%/foo/bar.JPeg', null, 'jpeg'];
yield ['%MEDIA%/foo/bar.JPeg', 'test.txt', 'txt'];
yield ['%MEDIA%/foo/bar', null, ''];
yield ['%MEDIA%/foo.bar', 'bar', ''];
yield ['http://google.de', null, null];
yield ['https://foo.bar', null, null];
yield ['https://foo.bar/test.jpeg', null, null];
yield ['test', null, null];
yield ['test.txt', null, null];
}
/**
@ -177,21 +167,19 @@ class AttachmentTest extends TestCase
$this->assertSame($expected, $attachment->getExtension());
}
public function pictureDataProvider(): array
public function pictureDataProvider(): \Iterator
{
return [
['%MEDIA%/foo/bar.txt', false],
['https://test.de/picture.jpeg', true],
['https://test.de/picture.png?test=fdsj&width=34', true],
['https://invalid.invalid/file.txt', false],
['http://infsf.inda/file.zip?test', false],
['https://test.de', true],
['https://invalid.com/invalid/pic', true],
['%MEDIA%/foo/bar.jpeg', true],
['%MEDIA%/foo/bar.webp', true],
['%MEDIA%/foo', false],
['%SECURE%/foo.txt/test', false],
];
yield ['%MEDIA%/foo/bar.txt', false];
yield ['https://test.de/picture.jpeg', true];
yield ['https://test.de/picture.png?test=fdsj&width=34', true];
yield ['https://invalid.invalid/file.txt', false];
yield ['http://infsf.inda/file.zip?test', false];
yield ['https://test.de', true];
yield ['https://invalid.com/invalid/pic', true];
yield ['%MEDIA%/foo/bar.jpeg', true];
yield ['%MEDIA%/foo/bar.webp', true];
yield ['%MEDIA%/foo', false];
yield ['%SECURE%/foo.txt/test', false];
}
/**
@ -204,16 +192,14 @@ class AttachmentTest extends TestCase
$this->assertSame($expected, $attachment->isPicture());
}
public function builtinDataProvider(): array
public function builtinDataProvider(): \Iterator
{
return [
['', false],
['%MEDIA%/foo/bar.txt', false],
['%BASE%/foo/bar.txt', false],
['/', false],
['https://google.de', false],
['%FOOTPRINTS%/foo/bar.txt', true],
];
yield ['', false];
yield ['%MEDIA%/foo/bar.txt', false];
yield ['%BASE%/foo/bar.txt', false];
yield ['/', false];
yield ['https://google.de', false];
yield ['%FOOTPRINTS%/foo/bar.txt', true];
}
/**
@ -226,13 +212,11 @@ class AttachmentTest extends TestCase
$this->assertSame($expected, $attachment->isBuiltIn());
}
public function hostDataProvider(): array
public function hostDataProvider(): \Iterator
{
return [
['%MEDIA%/foo/bar.txt', null],
['https://www.google.de/test.txt', 'www.google.de'],
['https://foo.bar/test?txt=test', 'foo.bar'],
];
yield ['%MEDIA%/foo/bar.txt', null];
yield ['https://www.google.de/test.txt', 'www.google.de'];
yield ['https://foo.bar/test?txt=test', 'foo.bar'];
}
/**
@ -245,13 +229,11 @@ class AttachmentTest extends TestCase
$this->assertSame($expected, $attachment->getHost());
}
public function filenameProvider(): array
public function filenameProvider(): \Iterator
{
return [
['%MEDIA%/foo/bar.txt', null, 'bar.txt'],
['%MEDIA%/foo/bar.JPeg', 'test.txt', 'test.txt'],
['https://www.google.de/test.txt', null, null],
];
yield ['%MEDIA%/foo/bar.txt', null, 'bar.txt'];
yield ['%MEDIA%/foo/bar.JPeg', 'test.txt', 'test.txt'];
yield ['https://www.google.de/test.txt', null, null];
}
/**

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\Tests\Entity\LogSystem;
use App\Entity\LogSystem\LogLevel;

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\Tests\Entity\LogSystem;
use App\Entity\Attachments\Attachment;

View file

@ -46,29 +46,25 @@ use PHPUnit\Framework\TestCase;
class PartParameterTest extends TestCase
{
public function valueWithUnitDataProvider(): array
public function valueWithUnitDataProvider(): \Iterator
{
return [
['1', 1.0, ''],
['1 V', 1.0, 'V'],
['1.23', 1.23, ''],
['1.23 V', 1.23, 'V'],
];
yield ['1', 1.0, ''];
yield ['1 V', 1.0, 'V'];
yield ['1.23', 1.23, ''];
yield ['1.23 V', 1.23, 'V'];
}
public function formattedValueDataProvider(): array
public function formattedValueDataProvider(): \Iterator
{
return [
['Text Test', null, null, null, 'V', 'Text Test'],
['10.23 V', null, 10.23, null, 'V', ''],
['10.23 V [Text]', null, 10.23, null, 'V', 'Text'],
['max. 10.23 V', null, null, 10.23, 'V', ''],
['max. 10.23 [Text]', null, null, 10.23, '', 'Text'],
['min. 10.23 V', 10.23, null, null, 'V', ''],
['10.23 V ... 11 V', 10.23, null, 11, 'V', ''],
['10.23 V (9 V ... 11 V)', 9, 10.23, 11, 'V', ''],
['10.23 V (9 V ... 11 V) [Test]', 9, 10.23, 11, 'V', 'Test'],
];
yield ['Text Test', null, null, null, 'V', 'Text Test'];
yield ['10.23 V', null, 10.23, null, 'V', ''];
yield ['10.23 V [Text]', null, 10.23, null, 'V', 'Text'];
yield ['max. 10.23 V', null, null, 10.23, 'V', ''];
yield ['max. 10.23 [Text]', null, null, 10.23, '', 'Text'];
yield ['min. 10.23 V', 10.23, null, null, 'V', ''];
yield ['10.23 V ... 11 V', 10.23, null, 11, 'V', ''];
yield ['10.23 V (9 V ... 11 V)', 9, 10.23, 11, 'V', ''];
yield ['10.23 V (9 V ... 11 V) [Test]', 9, 10.23, 11, 'V', 'Test'];
}
/**

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\Tests\Entity\Parts;
use App\Entity\Parts\InfoProviderReference;
@ -46,9 +48,9 @@ class InfoProviderReferenceTest extends TestCase
//The provider reference instance should return true for the providerCreated method
$this->assertTrue($provider->isProviderCreated());
//And the correct values for all other methods
$this->assertEquals('test', $provider->getProviderKey());
$this->assertEquals('id', $provider->getProviderId());
$this->assertEquals('url', $provider->getProviderUrl());
$this->assertSame('test', $provider->getProviderKey());
$this->assertSame('id', $provider->getProviderId());
$this->assertSame('url', $provider->getProviderUrl());
$this->assertNotNull($provider->getLastUpdated());
}
@ -60,9 +62,9 @@ class InfoProviderReferenceTest extends TestCase
//The provider reference instance should return true for the providerCreated method
$this->assertTrue($reference->isProviderCreated());
//And the correct values for all other methods
$this->assertEquals('test', $reference->getProviderKey());
$this->assertEquals('id', $reference->getProviderId());
$this->assertEquals('url', $reference->getProviderUrl());
$this->assertSame('test', $reference->getProviderKey());
$this->assertSame('id', $reference->getProviderId());
$this->assertSame('url', $reference->getProviderUrl());
$this->assertNotNull($reference->getLastUpdated());
}
}

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\Tests\Entity\Parts;
use App\Entity\Parts\AssociationType;
@ -34,7 +36,7 @@ class PartAssociationTest extends TestCase
$assoc->setOtherType('Custom Type');
//If the type is not OTHER the translation key should be the same as the type
$this->assertEquals($assoc->getType()->getTranslationKey(), $assoc->getTypeTranslationKey());
$this->assertSame($assoc->getType()->getTranslationKey(), $assoc->getTypeTranslationKey());
//If the type is OTHER the translation key should be the other type
$assoc->setType(AssociationType::OTHER);

View file

@ -55,15 +55,15 @@ class PartTest extends TestCase
//Without a set measurement unit the part must return an int
$part->setMinAmount(1.345);
$this->assertSame(1.0, $part->getMinAmount());
$this->assertEqualsWithDelta(1.0, $part->getMinAmount(), PHP_FLOAT_EPSILON);
//If a non-int-based unit is assigned, a float is returned
$part->setPartUnit($measurement_unit);
$this->assertSame(1.345, $part->getMinAmount());
$this->assertEqualsWithDelta(1.345, $part->getMinAmount(), PHP_FLOAT_EPSILON);
//If an int-based unit is assigned an int is returned
$measurement_unit->setIsInteger(true);
$this->assertSame(1.0, $part->getMinAmount());
$this->assertEqualsWithDelta(1.0, $part->getMinAmount(), PHP_FLOAT_EPSILON);
}
public function testUseFloatAmount(): void
@ -87,7 +87,7 @@ class PartTest extends TestCase
$measurement_unit = new MeasurementUnit();
$datetime = new DateTime();
$this->assertSame(0.0, $part->getAmountSum());
$this->assertEqualsWithDelta(0.0, $part->getAmountSum(), PHP_FLOAT_EPSILON);
$part->addPartLot((new PartLot())->setAmount(3.141));
$part->addPartLot((new PartLot())->setAmount(10.0));
@ -98,15 +98,15 @@ class PartTest extends TestCase
->setExpirationDate($datetime->setTimestamp(strtotime('now -1 hour')))
);
$this->assertSame(13.0, $part->getAmountSum());
$this->assertEqualsWithDelta(13.0, $part->getAmountSum(), PHP_FLOAT_EPSILON);
$part->setPartUnit($measurement_unit);
$this->assertSame(13.141, $part->getAmountSum());
$this->assertEqualsWithDelta(13.141, $part->getAmountSum(), PHP_FLOAT_EPSILON);
//1 billion part lot
$part->addPartLot((new PartLot())->setAmount(1_000_000_000));
$this->assertSame(1_000_000_013.141, $part->getAmountSum());
$this->assertEqualsWithDelta(1_000_000_013.141, $part->getAmountSum(), PHP_FLOAT_EPSILON);
$measurement_unit->setIsInteger(true);
$this->assertSame(1_000_000_013.0, $part->getAmountSum());
$this->assertEqualsWithDelta(1_000_000_013.0, $part->getAmountSum(), PHP_FLOAT_EPSILON);
}
}

View file

@ -60,18 +60,18 @@ class PricedetailTest extends TestCase
$orderdetail2->method('getPart')->willReturn($part2);
//By default a price detail returns 1
$this->assertSame(1.0, $pricedetail->getPriceRelatedQuantity());
$this->assertEqualsWithDelta(1.0, $pricedetail->getPriceRelatedQuantity(), PHP_FLOAT_EPSILON);
$pricedetail->setOrderdetail($orderdetail);
$pricedetail->setPriceRelatedQuantity(10.23);
$this->assertSame(10.0, $pricedetail->getPriceRelatedQuantity());
$this->assertEqualsWithDelta(10.0, $pricedetail->getPriceRelatedQuantity(), PHP_FLOAT_EPSILON);
//Price related quantity must not be zero!
$pricedetail->setPriceRelatedQuantity(0.23);
$this->assertSame(1.0, $pricedetail->getPriceRelatedQuantity());
$this->assertEqualsWithDelta(1.0, $pricedetail->getPriceRelatedQuantity(), PHP_FLOAT_EPSILON);
//With a part that has a float amount unit, also values like 0.23 can be returned
$pricedetail->setOrderdetail($orderdetail2);
$this->assertSame(0.23, $pricedetail->getPriceRelatedQuantity());
$this->assertEqualsWithDelta(0.23, $pricedetail->getPriceRelatedQuantity(), PHP_FLOAT_EPSILON);
}
public function testGetMinDiscountQuantity(): void
@ -88,17 +88,17 @@ class PricedetailTest extends TestCase
$orderdetail2->method('getPart')->willReturn($part2);
//By default a price detail returns 1
$this->assertSame(1.0, $pricedetail->getMinDiscountQuantity());
$this->assertEqualsWithDelta(1.0, $pricedetail->getMinDiscountQuantity(), PHP_FLOAT_EPSILON);
$pricedetail->setOrderdetail($orderdetail);
$pricedetail->setMinDiscountQuantity(10.23);
$this->assertSame(10.0, $pricedetail->getMinDiscountQuantity());
$this->assertEqualsWithDelta(10.0, $pricedetail->getMinDiscountQuantity(), PHP_FLOAT_EPSILON);
//Price related quantity must not be zero!
$pricedetail->setMinDiscountQuantity(0.23);
$this->assertSame(1.0, $pricedetail->getMinDiscountQuantity());
$this->assertEqualsWithDelta(1.0, $pricedetail->getMinDiscountQuantity(), PHP_FLOAT_EPSILON);
//With a part that has a float amount unit, also values like 0.23 can be returned
$pricedetail->setOrderdetail($orderdetail2);
$this->assertSame(0.23, $pricedetail->getMinDiscountQuantity());
$this->assertEqualsWithDelta(0.23, $pricedetail->getMinDiscountQuantity(), PHP_FLOAT_EPSILON);
}
}

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\Tests\Entity\UserSystem;
use App\Entity\UserSystem\ApiTokenType;
@ -28,7 +30,7 @@ class ApiTokenTypeTest extends TestCase
public function testGetTokenPrefix(): void
{
$this->assertEquals('tcp_', ApiTokenType::PERSONAL_ACCESS_TOKEN->getTokenPrefix());
$this->assertSame('tcp_', ApiTokenType::PERSONAL_ACCESS_TOKEN->getTokenPrefix());
}
public function testGetTypeFromToken(): void

View file

@ -45,13 +45,11 @@ class UserTest extends TestCase
$this->assertSame('John (@username)', $user->getFullName(true));
}
public function googleAuthenticatorEnabledDataProvider(): array
public function googleAuthenticatorEnabledDataProvider(): \Iterator
{
return [
[null, false],
['', false],
['SSSk38498', true],
];
yield [null, false];
yield ['', false];
yield ['SSSk38498', true];
}
/**