Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up psalm to level 2 #555

Merged
merged 58 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7587374
Up psalm to level 2
jordisala1991 Mar 22, 2023
8d89c88
Drop php < 8 code
jordisala1991 Mar 22, 2023
5efea1d
Update Issue156Contact.php
jordisala1991 Mar 22, 2023
eb5d273
Update AbstractDataEntity.php
jordisala1991 Mar 22, 2023
a0fa352
Update Issue308User.php
jordisala1991 Mar 22, 2023
3073a09
Update DataContainerEntity.php
jordisala1991 Mar 22, 2023
27e260a
Update OwnerEntity.php
jordisala1991 Mar 22, 2023
d2fa27f
Update Page.php
jordisala1991 Mar 22, 2023
2875f49
Update BaseTest.php
jordisala1991 Mar 22, 2023
e1024ca
Actualizar BaseTest.php
jordisala1991 Mar 22, 2023
dfdc8c2
Actualizar BaseTest.php
jordisala1991 Mar 22, 2023
fb0e733
Actualizar BaseTest.php
jordisala1991 Mar 22, 2023
29efc21
Actualizar BaseTest.php
jordisala1991 Mar 22, 2023
f951562
Actualizar BaseTest.php
jordisala1991 Mar 22, 2023
64d3ad2
Update AuditedCollection.php
jordisala1991 Mar 22, 2023
13b7e27
Update AuditedCollection.php
jordisala1991 Mar 22, 2023
6585cee
Update AuditedCollection.php
jordisala1991 Mar 22, 2023
312d64c
Update AuditedCollection.php
jordisala1991 Mar 22, 2023
34b25be
Actualizar AuditedCollection.php
jordisala1991 Mar 22, 2023
eb0fc36
Update src/Collection/AuditedCollection.php
jordisala1991 Mar 22, 2023
e3ece7e
Actualizar AuditedCollection.php
jordisala1991 Mar 22, 2023
ef2d5c8
Actualizar AuditedCollection.php
jordisala1991 Mar 22, 2023
898b8fa
Actualizar AuditedCollection.php
jordisala1991 Mar 23, 2023
d69cea7
Actualizar AuditConfiguration.php
jordisala1991 Mar 23, 2023
e9f90e2
Actualizar LogRevisionsListener.php
jordisala1991 Mar 23, 2023
af3fb5e
Update src/EventListener/LogRevisionsListener.php
jordisala1991 Mar 23, 2023
aaf4a5b
Actualizar LogRevisionsListener.php
jordisala1991 Mar 23, 2023
e548d03
Actualizar psalm.xml
jordisala1991 Mar 23, 2023
3c649ec
Actualizar AuditedCollection.php
jordisala1991 Mar 23, 2023
adca8ca
Actualizar BaseTest.php
jordisala1991 Mar 23, 2023
e4eb4b1
Actualizar CoreTest.php
jordisala1991 Mar 23, 2023
130a43f
Actualizar ClockTest.php
jordisala1991 Mar 23, 2023
c1d508d
Actualizar ClockTest.php
jordisala1991 Mar 23, 2023
04bf7b4
Actualizar CoreTest.php
jordisala1991 Mar 23, 2023
2eae445
Actualizar CoreTest.php
jordisala1991 Mar 23, 2023
6fb0a05
Actualizar Issue111Test.php
jordisala1991 Mar 23, 2023
1d9b921
Actualizar Issue156Test.php
jordisala1991 Mar 23, 2023
1662349
Actualizar Issue196Test.php
jordisala1991 Mar 23, 2023
de6c186
Actualizar Issue198Test.php
jordisala1991 Mar 23, 2023
1feefc8
Actualizar Issue308Test.php
jordisala1991 Mar 23, 2023
a6daad8
Actualizar Issue318Test.php
jordisala1991 Mar 23, 2023
2decfad
Actualizar Issue31Test.php
jordisala1991 Mar 23, 2023
95046ec
Actualizar Issue87Test.php
jordisala1991 Mar 23, 2023
ed9fd88
Actualizar Issue9Test.php
jordisala1991 Mar 23, 2023
79d6c97
Actualizar RelationTest.php
jordisala1991 Mar 23, 2023
e6b057e
Actualizar IssueConvertToPHPTest.php
jordisala1991 Mar 23, 2023
6a736db
Actualizar IssueDuplicateRevisionTest.php
jordisala1991 Mar 23, 2023
ffec6d1
Actualizar IssueEntityWithEnumTest.php
jordisala1991 Mar 23, 2023
e308baf
Actualizar IssueEscapedColumnsTest.php
jordisala1991 Mar 23, 2023
132df69
Actualizar IssueSelfReferencingManyToManyEntityTest.php
jordisala1991 Mar 23, 2023
900f739
Actualizar IssueUnidirectionalManyToManyEntityTest.php
jordisala1991 Mar 23, 2023
89f2c34
Actualizar Issue308Test.php
jordisala1991 Mar 23, 2023
61d5d11
Actualizar IssueEntityWithEnumTest.php
jordisala1991 Mar 23, 2023
119d857
Actualizar ClockTest.php
jordisala1991 Mar 23, 2023
ced2f35
Actualizar Issue318Test.php
jordisala1991 Mar 23, 2023
7a4ea22
Actualizar CoreTest.php
jordisala1991 Mar 23, 2023
77f98cd
Actualizar rector.php
jordisala1991 Mar 23, 2023
29aaa0c
Update rector.php
jordisala1991 Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorLevel="3" errorBaseline="psalm-baseline.xml" findUnusedPsalmSuppress="true" findUnusedBaselineEntry="true" findUnusedCode="false" resolveFromConfigFile="true">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorLevel="2" errorBaseline="psalm-baseline.xml" findUnusedPsalmSuppress="true" findUnusedBaselineEntry="true" findUnusedCode="false" resolveFromConfigFile="true">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand All @@ -12,4 +12,9 @@
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<!-- Psalm equivalent of PHPStan config `treatPhpDocTypesAsCertain: false` -->
<DocblockTypeContradiction errorLevel="suppress"/>
<RedundantConditionGivenDocblockType errorLevel="suppress"/>
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
CountOnNullRector::class,
ExceptionHandlerTypehintRector::class,
UnionTypesRector::class => [
__DIR__.'/src/AuditConfiguration.php',
__DIR__.'/src/AuditReader.php',
__DIR__.'/src/Controller/AuditController.php',
__DIR__.'/src/EventListener/LogRevisionsListener.php',
__DIR__.'/src/Revision.php',
],
Expand Down
2 changes: 1 addition & 1 deletion src/AuditConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function getCurrentUsername()
}

/**
* @param callable $usernameCallable
* @param callable|null $usernameCallable
*/
public function setUsernameCallable($usernameCallable): void
{
Expand Down
27 changes: 19 additions & 8 deletions src/Collection/AuditedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct(
* @return true
*/
#[\ReturnTypeWillChange]
public function add($element)
public function add(mixed $element)
{
throw new AuditedCollectionException('The AuditedCollection is read-only');
}
Expand All @@ -100,7 +100,7 @@ public function clear(): void
* @return bool
*/
#[\ReturnTypeWillChange]
public function contains($element)
public function contains(mixed $element)
{
$this->forceLoad();

Expand All @@ -123,6 +123,8 @@ public function isEmpty()
}

/**
* @param string|int $key
*
* @return T|null
*/
#[\ReturnTypeWillChange]
Expand All @@ -135,13 +137,17 @@ public function remove($key)
* @return bool
*/
#[\ReturnTypeWillChange]
public function removeElement($element)
public function removeElement(mixed $element)
{
throw new AuditedCollectionException('Audited collections does not support removal');
}

/**
* @param int|string $key
*
* @return bool
*
* @phpstan-param TKey $key
*/
#[\ReturnTypeWillChange]
public function containsKey($key)
Expand All @@ -152,6 +158,8 @@ public function containsKey($key)
}

/**
* @param string|int $key
*
* @return object
*
* @phpstan-return T
Expand Down Expand Up @@ -346,14 +354,17 @@ public function partition(\Closure $p)
* @return TKey|false
*/
#[\ReturnTypeWillChange]
public function indexOf($element)
public function indexOf(mixed $element)
{
$this->forceLoad();

return $this->loadedEntities->indexOf($element);
}

/**
* @param int $offset
* @param int|null $length
*
* @return object[]
*
* @phpstan-return array<TKey,T>
Expand Down Expand Up @@ -381,7 +392,7 @@ public function getIterator()
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
public function offsetExists(mixed $offset)
{
$this->forceLoad();

Expand All @@ -394,7 +405,7 @@ public function offsetExists($offset)
* @phpstan-return T
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet(mixed $offset)
{
if ($this->loadedEntities->offsetExists($offset)) {
$entity = $this->loadedEntities->offsetGet($offset);
Expand All @@ -417,12 +428,12 @@ public function offsetGet($offset)
return $resolvedEntity;
}

public function offsetSet($offset, $value): void
public function offsetSet(mixed $offset, mixed $value): void
{
throw new AuditedCollectionException('AuditedCollection is read-only');
}

public function offsetUnset($offset): void
public function offsetUnset(mixed $offset): void
{
throw new AuditedCollectionException('Audited collections does not support removal');
}
Expand Down
19 changes: 8 additions & 11 deletions src/EventListener/LogRevisionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\UnitOfWork;
use Doctrine\ORM\Utility\PersisterHelper;
use Doctrine\Persistence\Mapping\MappingException;
use Psr\Clock\ClockInterface;
use SimpleThings\EntityAudit\AuditConfiguration;
Expand Down Expand Up @@ -183,7 +184,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
foreach ($this->deferredChangedManyToManyEntityRevisionsToPersist as $deferredChangedManyToManyEntityRevisionToPersist) {
$this->recordRevisionForManyToManyEntity(
$deferredChangedManyToManyEntityRevisionToPersist->getEntity(),
$em->getConnection(),
$em,
$deferredChangedManyToManyEntityRevisionToPersist->getRevType(),
$deferredChangedManyToManyEntityRevisionToPersist->getEntityData(),
$deferredChangedManyToManyEntityRevisionToPersist->getAssoc(),
Expand Down Expand Up @@ -361,12 +362,7 @@ private function getRevisionId(Connection $conn)
]
);

$platform = $conn->getDatabasePlatform();
$sequenceName = $platform->supportsSequences()
? $platform->getIdentitySequenceName($this->config->getRevisionTableName(), 'id')
: null;

$revisionId = $conn->lastInsertId($sequenceName);
$revisionId = $conn->lastInsertId();
if (false === $revisionId) {
throw new \RuntimeException('Unable to retrieve the last revision id.');
}
Expand Down Expand Up @@ -545,7 +541,7 @@ private function saveRevisionEntityData(EntityManagerInterface $em, ClassMetadat
// so we have to defer writing the revision record to the DB to the postFlush event by which point we know that the entity is gonna be flushed and have the ID assigned
$this->deferredChangedManyToManyEntityRevisionsToPersist[] = new DeferredChangedManyToManyEntityRevisionToPersist($relatedEntity, $revType, $entityData, $assoc, $class, $targetClass);
} else {
$this->recordRevisionForManyToManyEntity($relatedEntity, $conn, $revType, $entityData, $assoc, $class, $targetClass);
$this->recordRevisionForManyToManyEntity($relatedEntity, $em, $revType, $entityData, $assoc, $class, $targetClass);
}
}
}
Expand Down Expand Up @@ -612,19 +608,20 @@ private function saveRevisionEntityData(EntityManagerInterface $em, ClassMetadat
* @param ClassMetadata<object> $class
* @param ClassMetadata<object> $targetClass
*/
private function recordRevisionForManyToManyEntity(object $relatedEntity, Connection $conn, string $revType, array $entityData, array $assoc, ClassMetadata $class, ClassMetadata $targetClass): void
private function recordRevisionForManyToManyEntity(object $relatedEntity, EntityManagerInterface $em, string $revType, array $entityData, array $assoc, ClassMetadata $class, ClassMetadata $targetClass): void
{
$conn = $em->getConnection();
$joinTableParams = [$this->getRevisionId($conn), $revType];
$joinTableTypes = [\PDO::PARAM_INT, \PDO::PARAM_STR];
foreach ($assoc['relationToSourceKeyColumns'] as $targetColumn) {
$joinTableParams[] = $entityData[$class->fieldNames[$targetColumn]];
$joinTableTypes[] = $class->getTypeOfColumn($targetColumn);
$joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $class, $em);
}
foreach ($assoc['relationToTargetKeyColumns'] as $targetColumn) {
$reflField = $targetClass->reflFields[$targetClass->fieldNames[$targetColumn]];
\assert(null !== $reflField);
$joinTableParams[] = $reflField->getValue($relatedEntity);
$joinTableTypes[] = $targetClass->getTypeOfColumn($targetColumn);
$joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $em);
}
$conn->executeStatement(
$this->getInsertJoinTableRevisionSQL($class, $targetClass, $assoc),
Expand Down
24 changes: 7 additions & 17 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ abstract class BaseTest extends TestCase
protected static $conn;

/**
* NEXT_MAJOR: Use `\Doctrine\ORM\EntityManagerInterface` instead.
*
* @var EntityManager
* NEXT_MAJOR: Change typehint to EntityManagerInterface.
*/
protected $em;
protected ?EntityManager $em = null;

/**
* @var AuditManager
*/
protected $auditManager;
protected ?AuditManager $auditManager = null;

/**
* @var string[]
Expand Down Expand Up @@ -98,12 +93,7 @@ protected function getEntityManager(): EntityManager
$mappingPaths[] = __DIR__.'/Fixtures/PHP81Issue';
}

if (version_compare(\PHP_VERSION, '8.0.0', '>=')) {
$config = ORMSetup::createAttributeMetadataConfiguration($mappingPaths, true);
} else {
$config = ORMSetup::createAnnotationMetadataConfiguration($mappingPaths, true);
}

$config = ORMSetup::createAttributeMetadataConfiguration($mappingPaths, true);
$connection = $this->_getConnection($config);

$this->em = new EntityManager($connection, $config, new EventManager());
Expand Down Expand Up @@ -158,10 +148,10 @@ protected function getAuditManager(): AuditManager
$auditConfig->setGlobalIgnoreColumns(['ignoreme']);
$auditConfig->setUsernameCallable(static fn (): string => 'beberlei');

$auditManager = new AuditManager($auditConfig, $this->getClock());
$auditManager->registerEvents($this->getEntityManager()->getEventManager());
$this->auditManager = new AuditManager($auditConfig, $this->getClock());
$this->auditManager->registerEvents($this->getEntityManager()->getEventManager());

return $this->auditManager = $auditManager;
return $this->auditManager;
}

protected function getClock(): ?ClockInterface
Expand Down
8 changes: 5 additions & 3 deletions tests/ClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ final class ClockTest extends BaseTest

public function testFixedClockIsUsed(): void
{
$em = $this->getEntityManager();

$user = new Issue318User();
$user->setAlias('alias');
$this->em->persist($user);
$this->em->flush();
$em->persist($user);
$em->flush();

$userId = $user->getId();

\assert(\is_int($userId));

$reader = $this->auditManager->createAuditReader($this->em);
$reader = $this->getAuditManager()->createAuditReader($em);

$revisions = $reader->findRevisions(Issue318User::class, $userId);

Expand Down
Loading