Skip to content

Commit 78e62ae

Browse files
Add many typings from PHPDoc (#6)
* Add many typings from PHPDoc * Apply suggestions from code review Co-authored-by: Bob van de Vijver <[email protected]> --------- Co-authored-by: Bob van de Vijver <[email protected]>
1 parent 804fa3e commit 78e62ae

13 files changed

+81
-401
lines changed

BobvEntityHistoryBundle.php

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Symfony\Component\HttpKernel\Bundle\Bundle;
66

77
/**
8-
* Class BobVEntityHistoryBundle
9-
*
108
* @author BobV
119
*/
1210
class BobvEntityHistoryBundle extends Bundle

Configuration/HistoryConfiguration.php

+15-76
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
66

77
/**
8-
* Class HistoryConfiguration
9-
*
108
* Based on the work of
119
* SimpleThings\EntityAudit
1210
* Benjamin Eberlei <[email protected]>
@@ -16,7 +14,6 @@
1614
*/
1715
class HistoryConfiguration
1816
{
19-
2017
// Configuration variables
2118
protected $classes;
2219
protected $prefix;
@@ -26,70 +23,37 @@ class HistoryConfiguration
2623
protected $deletedAtField;
2724
protected $deletedByField;
2825
protected $deletedByMethod;
29-
30-
/**
31-
* @var array
32-
*/
33-
private $changes = array();
26+
private array $changes = [];
3427

3528
public function __construct(private readonly AuthorizationCheckerInterface $authorizationChecker) {
3629
}
3730

38-
/**
39-
* @return mixed
40-
*/
41-
public function getClasses() {
31+
public function getClasses(): mixed {
4232
return $this->classes;
4333
}
4434

45-
/**
46-
* @return mixed
47-
*/
48-
public function getPrefix() {
35+
public function getPrefix(): mixed {
4936
return $this->prefix;
5037
}
5138

52-
/**
53-
* @return mixed
54-
*/
55-
public function getRevisionFieldName() {
39+
public function getRevisionFieldName(): mixed {
5640
return $this->revisionFieldName;
5741
}
5842

59-
/**
60-
* @return mixed
61-
*/
62-
public function getRevisionTypeFieldName() {
43+
public function getRevisionTypeFieldName(): mixed {
6344
return $this->revisionTypeFieldName;
6445
}
6546

66-
/**
67-
* @return mixed
68-
*/
69-
public function getSuffix() {
47+
public function getSuffix(): mixed {
7048
return $this->suffix;
7149
}
7250

73-
/**
74-
* @param $class
75-
*
76-
* @return string
77-
*/
78-
public function getTableName($class) {
51+
public function getTableName($class): string {
7952
return $this->prefix . $class . $this->suffix;
8053
}
8154

82-
/**
83-
* @param $prefix
84-
* @param $suffix
85-
* @param $revFieldName
86-
* @param $revTypeFieldName
87-
* @param $classes
88-
* @param $deletedAtField
89-
* @param $deletedByField
90-
* @param $deletedByMethod
91-
*/
92-
public function injectVars($prefix, $suffix, $revFieldName, $revTypeFieldName, $classes, $deletedAtField, $deletedByField, $deletedByMethod) {
55+
public function injectVars($prefix, $suffix, $revFieldName, $revTypeFieldName, $classes, $deletedAtField, $deletedByField, $deletedByMethod): void
56+
{
9357
$this->prefix = $prefix;
9458
$this->suffix = $suffix;
9559
$this->revisionFieldName = $revFieldName;
@@ -100,33 +64,19 @@ public function injectVars($prefix, $suffix, $revFieldName, $revTypeFieldName, $
10064
$this->deletedByMethod = $deletedByMethod;
10165
}
10266

103-
/**
104-
* @param $entityName
105-
*
106-
* @return mixed
107-
*/
108-
public function isLogged($entityName) {
67+
public function isLogged($entityName): bool {
10968
return array_key_exists($entityName, $this->classes);
11069
}
11170

112-
/**
113-
* @return mixed
114-
*/
115-
public function getDeletedAtField() {
71+
public function getDeletedAtField(): mixed {
11672
return $this->deletedAtField;
11773
}
11874

119-
/**
120-
* @return mixed
121-
*/
122-
public function getDeletedByField() {
75+
public function getDeletedByField(): mixed {
12376
return $this->deletedByField;
12477
}
12578

126-
/**
127-
* @return mixed
128-
*/
129-
public function getDeletedByValue() {
79+
public function getDeletedByValue(): mixed {
13080
$method = $this->deletedByMethod;
13181
try {
13282
return $this->authorizationChecker->$method();
@@ -135,13 +85,7 @@ public function getDeletedByValue() {
13585
}
13686
}
13787

138-
/**
139-
* @param $className
140-
* @param $id
141-
*
142-
* @return bool
143-
*/
144-
public function isReverted($className, $id) {
88+
public function isReverted($className, $id): bool {
14589
if (isset($this->changes[$className]) && in_array($id, $this->changes[$className])) {
14690
unset($this->changes[$className][$id]);
14791
return true;
@@ -150,15 +94,10 @@ public function isReverted($className, $id) {
15094
return false;
15195
}
15296

153-
/**
154-
* @param $className
155-
* @param $id
156-
*/
157-
public function setReverted($className, $id) {
97+
public function setReverted($className, $id): void {
15898
if (!isset($this->changes[$className])) {
15999
$this->changes[$className] = [];
160100
}
161101
$this->changes[$className][] = $id;
162102
}
163-
164103
}

DependencyInjection/BobvEntityHistoryExtension.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
99

1010
/**
11-
* Class BobVEntityHistoryExtension
12-
*
1311
* Based on the work of
1412
* SimpleThings\EntityAudit
1513
* Benjamin Eberlei <[email protected]>
@@ -19,7 +17,7 @@
1917
*/
2018
class BobvEntityHistoryExtension extends Extension
2119
{
22-
public function load(array $configs, ContainerBuilder $container) {
20+
public function load(array $configs, ContainerBuilder $container): void {
2321
$config = $this->processConfiguration(new Configuration(), $configs);
2422

2523
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

DependencyInjection/Configuration.php

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Symfony\Component\Config\Definition\ConfigurationInterface;
77

88
/**
9-
* Class Configuration
10-
*
119
* Based on the work of
1210
* SimpleThings\EntityAudit
1311
* Benjamin Eberlei <[email protected]>

EventSubscriber/CreateSchemaSubscriber.php

+7-25
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Doctrine\ORM\Tools\ToolEvents;
1010

1111
/**
12-
* Class CreateSchemaSubscriber
13-
*
1412
* Based on the work of
1513
* SimpleThings\EntityAudit
1614
* Benjamin Eberlei <[email protected]>
@@ -20,47 +18,31 @@
2018
*/
2119
class CreateSchemaSubscriber implements EventSubscriber
2220
{
23-
24-
/**
25-
* @var HistoryConfiguration
26-
*/
27-
private $config;
28-
29-
/**
30-
* @param HistoryConfiguration $configuration
31-
*/
32-
public function __construct(HistoryConfiguration $configuration)
21+
public function __construct(private readonly HistoryConfiguration $configuration)
3322
{
34-
$this->config = $configuration;
3523
}
3624

37-
/**
38-
* @return array
39-
*/
40-
public function getSubscribedEvents()
25+
public function getSubscribedEvents(): array
4126
{
42-
return array(
27+
return [
4328
ToolEvents::postGenerateSchemaTable
44-
);
29+
];
4530
}
4631

47-
/**
48-
* @param GenerateSchemaTableEventArgs $eventArgs
49-
*/
50-
public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs)
32+
public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs): void
5133
{
5234
$cm = $eventArgs->getClassMetadata();
5335

5436
// Check if the entity is logged
55-
if ($this->config->isLogged($cm->getName())) {
37+
if ($this->configuration->isLogged($cm->getName())) {
5638

5739
// Get needed vars
5840
$schema = $eventArgs->getSchema();
5941
$entityTable = $eventArgs->getClassTable();
6042

6143
// Create table
6244
$revisionTable = $schema->createTable(
63-
$this->config->getTableName($entityTable->getName())
45+
$this->configuration->getTableName($entityTable->getName())
6446
);
6547

6648
// Get id column (if any)

0 commit comments

Comments
 (0)