Skip to content

Commit

Permalink
Insight (#17)
Browse files Browse the repository at this point in the history
* fix symfony insight warnings

* insight badge

* fix symfony insight warnings

* fix symfony insight warnings

* fix symfony insight warnings
  • Loading branch information
jean-gui committed Oct 27, 2022
1 parent 3e89168 commit 486573d
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 256 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
vendor/*
composer.lock
.idea
13 changes: 3 additions & 10 deletions Annotation/Change.php
Expand Up @@ -13,19 +13,12 @@
*/
class Change
{
/**
* @var string
*/
public $event = LifecycleEvents::PROPERTY_CHANGED;

/**
* @var string
*/
public $class = LifecyclePropertyChangedEvent::class;
public string $event = LifecycleEvents::PROPERTY_CHANGED;
public string $class = LifecyclePropertyChangedEvent::class;

/**
* @var bool
* @deprecated to be removed in next major version and the class will always act as if it was set to true
*/
public $monitor_owning = false;
public bool $monitor_owning = false;
}
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Expand Up @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('w3_c_lifecycle_events');
$rootNode = $treeBuilder->getRootNode();
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/W3CLifecycleEventsExtension.php
Expand Up @@ -17,7 +17,7 @@ class W3CLifecycleEventsExtension extends Extension
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand Down
42 changes: 11 additions & 31 deletions Event/LifecycleCollectionChangedEvent.php
Expand Up @@ -9,30 +9,19 @@
*/
class LifecycleCollectionChangedEvent extends LifecycleEvent
{
/**
* @var string
*/
private $property;

/**
* @var array
*/
private $deletedElements;

/**
* @var array
*/
private $insertedElements;
private string $property;
private ?array $deletedElements;
private ?array $insertedElements;

/**
* Constructor.
*
* @param object $entity
* @param string $property
* @param array $deletedElements
* @param array $insertedElements
* @param object $entity
* @param string $property
* @param array|null $deletedElements
* @param array|null $insertedElements
*/
public function __construct($entity, $property, $deletedElements = null, $insertedElements = null)
public function __construct(object $entity, string $property, array $deletedElements = null, array $insertedElements = null)
{
parent::__construct($entity);

Expand All @@ -41,26 +30,17 @@ public function __construct($entity, $property, $deletedElements = null, $insert
$this->insertedElements = $insertedElements;
}

/**
* @return string
*/
public function getProperty()
public function getProperty(): string
{
return $this->property;
}

/**
* @return array|null
*/
public function getDeletedElements()
public function getDeletedElements(): ?array
{
return $this->deletedElements;
}

/**
* @return array|null
*/
public function getInsertedElements()
public function getInsertedElements(): ?array
{
return $this->insertedElements;
}
Expand Down
6 changes: 3 additions & 3 deletions Event/LifecycleDeletionEvent.php
Expand Up @@ -10,15 +10,15 @@
*/
class LifecycleDeletionEvent extends LifecycleEvent
{
protected $identifier;
protected array $identifier;

public function __construct($entity, $identifier = null)
public function __construct(object $entity, array $identifier = null)
{
parent::__construct($entity);
$this->identifier = $identifier;
}

public function getIdentifier()
public function getIdentifier(): array
{
return $this->identifier;
}
Expand Down
6 changes: 3 additions & 3 deletions Event/LifecycleEvent.php
Expand Up @@ -11,14 +11,14 @@
*/
class LifecycleEvent extends Event
{
protected $entity;
protected object $entity;

public function __construct($entity)
public function __construct(object $entity)
{
$this->entity = $entity;
}

public function getEntity()
public function getEntity(): object
{
return $this->entity;
}
Expand Down
6 changes: 3 additions & 3 deletions Event/LifecyclePropertyChangedEvent.php
Expand Up @@ -12,7 +12,7 @@ class LifecyclePropertyChangedEvent extends LifecycleEvent
/**
* @var string
*/
private $property;
private string $property;

/**
* @var mixed
Expand All @@ -32,7 +32,7 @@ class LifecyclePropertyChangedEvent extends LifecycleEvent
* @param mixed $oldValue
* @param mixed $newValue
*/
public function __construct($entity, $property, $oldValue = null, $newValue = null)
public function __construct(object $entity, string $property, $oldValue = null, $newValue = null)
{
parent::__construct($entity);

Expand All @@ -44,7 +44,7 @@ public function __construct($entity, $property, $oldValue = null, $newValue = nu
/**
* @return string
*/
public function getProperty()
public function getProperty(): string
{
return $this->property;
}
Expand Down
51 changes: 23 additions & 28 deletions Event/LifecycleUpdateEvent.php
Expand Up @@ -2,29 +2,24 @@

namespace W3C\LifecycleEventsBundle\Event;

use InvalidArgumentException;

/**
* LifecycleUpdateEvent is used when an entity is updated
*
* @author Jean-Guilhem Rouel <jean-gui@w3.org>
*/
class LifecycleUpdateEvent extends LifecycleEvent
{
/**
* @var array
*/
private $propertiesChangeSet;

/**
* @var array
*/
private $collectionsChangeSet;
private array $propertiesChangeSet;
private array $collectionsChangeSet;

/**
* @param object $entity the entity being modified
* @param array $propertiesChangeSet list of changes to properties
* @param array $collectionsChangeSet list of changes to collections
* @param object $entity the entity being modified
* @param array $propertiesChangeSet list of changes to properties
* @param array $collectionsChangeSet list of changes to collections
*/
public function __construct($entity, array $propertiesChangeSet = [], array $collectionsChangeSet = [])
public function __construct(object $entity, array $propertiesChangeSet = [], array $collectionsChangeSet = [])
{
parent::__construct($entity);

Expand All @@ -37,7 +32,7 @@ public function __construct($entity, array $propertiesChangeSet = [], array $col
*
* @return array
*/
public function getChangedProperties()
public function getChangedProperties(): array
{
return array_keys($this->propertiesChangeSet);
}
Expand All @@ -47,7 +42,7 @@ public function getChangedProperties()
*
* @return bool
*/
public function havePropertiesChanged()
public function havePropertiesChanged(): bool
{
return $this->propertiesChangeSet && count($this->propertiesChangeSet) > 0;
}
Expand All @@ -57,7 +52,7 @@ public function havePropertiesChanged()
*
* @return array
*/
public function getChangedCollections()
public function getChangedCollections(): array
{
return array_keys($this->collectionsChangeSet);
}
Expand All @@ -67,7 +62,7 @@ public function getChangedCollections()
*
* @return bool
*/
public function haveCollectionsChanged()
public function haveCollectionsChanged(): bool
{
return $this->collectionsChangeSet && count($this->collectionsChangeSet) > 0;
}
Expand All @@ -79,7 +74,7 @@ public function haveCollectionsChanged()
*
* @return boolean
*/
public function hasChangedField($field)
public function hasChangedField(string $field): bool
{
return isset($this->propertiesChangeSet[$field]) || isset($this->collectionsChangeSet[$field]);
}
Expand All @@ -91,7 +86,7 @@ public function hasChangedField($field)
*
* @return mixed
*/
public function getOldValue($field)
public function getOldValue(string $field)
{
$this->assertValidProperty($field);

Expand All @@ -105,7 +100,7 @@ public function getOldValue($field)
*
* @return mixed
*/
public function getNewValue($field)
public function getNewValue(string $field)
{
$this->assertValidProperty($field);

Expand All @@ -119,7 +114,7 @@ public function getNewValue($field)
*
* @return array
*/
public function getDeletedElements($field)
public function getDeletedElements(string $field): array
{
$this->assertValidCollection($field);

Expand All @@ -133,7 +128,7 @@ public function getDeletedElements($field)
*
* @return array
*/
public function getInsertedElements($field)
public function getInsertedElements(string $field): array
{
$this->assertValidCollection($field);

Expand All @@ -147,12 +142,12 @@ public function getInsertedElements($field)
*
* @return void
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
private function assertValidProperty($field)
private function assertValidProperty(string $field)
{
if (!isset($this->propertiesChangeSet[$field])) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Field "%s" is not a valid field of the entity "%s" org has not changed.',
$field,
get_class($this->getEntity())
Expand All @@ -167,12 +162,12 @@ private function assertValidProperty($field)
*
* @return void
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
private function assertValidCollection($field)
private function assertValidCollection(string $field)
{
if (!isset($this->collectionsChangeSet[$field])) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Field "%s" is not a valid collection of the entity "%s" org has not changed.',
$field,
get_class($this->getEntity())
Expand Down
14 changes: 2 additions & 12 deletions Event/PreAutoDispatchEvent.php
Expand Up @@ -12,24 +12,14 @@
*/
class PreAutoDispatchEvent extends Event
{
protected LifecycleEventsDispatcher $dispatcher;

/**
* @var LifecycleEventsDispatcher
*/
protected $dispatcher;

/**
* @param $dispatcher
*/
public function __construct(LifecycleEventsDispatcher $dispatcher)
{
$this->dispatcher = $dispatcher;
}

/**
* @return mixed
*/
public function getDispatcher()
public function getDispatcher(): LifecycleEventsDispatcher
{
return $this->dispatcher;
}
Expand Down

0 comments on commit 486573d

Please sign in to comment.