Skip to content

Commit 900a67b

Browse files
author
roadiz-ci
committed
feat: Refactored command signatures
1 parent bf66e51 commit 900a67b

File tree

88 files changed

+488
-1420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+488
-1420
lines changed

src/Bag/NodeTypes.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,20 @@
44

55
namespace RZ\Roadiz\CoreBundle\Bag;
66

7-
use Doctrine\Persistence\ManagerRegistry;
87
use RZ\Roadiz\Bag\LazyParameterBag;
98
use RZ\Roadiz\Contracts\NodeType\NodeTypeResolverInterface;
109
use RZ\Roadiz\CoreBundle\Entity\NodeType;
1110
use RZ\Roadiz\CoreBundle\Repository\NodeTypeRepository;
1211

13-
class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface
12+
final class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface
1413
{
15-
private ?NodeTypeRepository $repository = null;
16-
private ManagerRegistry $managerRegistry;
17-
18-
/**
19-
* @param ManagerRegistry $managerRegistry
20-
*/
21-
public function __construct(ManagerRegistry $managerRegistry)
14+
public function __construct(private readonly NodeTypeRepository $repository)
2215
{
2316
parent::__construct();
24-
$this->managerRegistry = $managerRegistry;
2517
}
2618

27-
/**
28-
* @return NodeTypeRepository
29-
*/
3019
public function getRepository(): NodeTypeRepository
3120
{
32-
if (null === $this->repository) {
33-
$this->repository = $this->managerRegistry->getRepository(NodeType::class);
34-
}
3521
return $this->repository;
3622
}
3723

src/Bag/Roles.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,17 @@
99
use RZ\Roadiz\CoreBundle\Entity\Role;
1010
use RZ\Roadiz\CoreBundle\Repository\RoleRepository;
1111

12-
class Roles extends LazyParameterBag
12+
final class Roles extends LazyParameterBag
1313
{
14-
private ManagerRegistry $managerRegistry;
15-
private ?RoleRepository $repository = null;
16-
17-
/**
18-
* @param ManagerRegistry $managerRegistry;
19-
*/
20-
public function __construct(ManagerRegistry $managerRegistry)
21-
{
14+
public function __construct(
15+
private readonly RoleRepository $repository,
16+
private readonly ManagerRegistry $managerRegistry
17+
) {
2218
parent::__construct();
23-
$this->managerRegistry = $managerRegistry;
2419
}
2520

26-
/**
27-
* @return RoleRepository
28-
*/
2921
public function getRepository(): RoleRepository
3022
{
31-
if (null === $this->repository) {
32-
$this->repository = $this->managerRegistry->getRepository(Role::class);
33-
}
3423
return $this->repository;
3524
}
3625

@@ -57,14 +46,15 @@ protected function populateParameters(): void
5746
*
5847
* @return Role
5948
*/
60-
public function get($key, $default = null): Role
49+
public function get(string $key, $default = null): Role
6150
{
6251
$role = parent::get($key, $default);
6352

6453
if (null === $role) {
6554
$role = new Role($key);
66-
$this->managerRegistry->getManagerForClass(Role::class)->persist($role);
67-
$this->managerRegistry->getManagerForClass(Role::class)->flush();
55+
$roleManager = $this->managerRegistry->getManagerForClass(Role::class);
56+
$roleManager->persist($role);
57+
$roleManager->flush();
6858
}
6959

7060
return $role;

src/Bag/Settings.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,25 @@
44

55
namespace RZ\Roadiz\CoreBundle\Bag;
66

7-
use Doctrine\Persistence\ManagerRegistry;
87
use RZ\Roadiz\Bag\LazyParameterBag;
98
use RZ\Roadiz\CoreBundle\Entity\Document;
109
use RZ\Roadiz\CoreBundle\Entity\Setting;
10+
use RZ\Roadiz\CoreBundle\Repository\DocumentRepository;
1111
use RZ\Roadiz\CoreBundle\Repository\SettingRepository;
1212
use Symfony\Component\Stopwatch\Stopwatch;
1313

14-
class Settings extends LazyParameterBag
14+
final class Settings extends LazyParameterBag
1515
{
16-
private ManagerRegistry $managerRegistry;
17-
private ?SettingRepository $repository = null;
18-
private Stopwatch $stopwatch;
19-
20-
public function __construct(ManagerRegistry $managerRegistry, Stopwatch $stopwatch)
21-
{
16+
public function __construct(
17+
private readonly SettingRepository $repository,
18+
private readonly DocumentRepository $documentRepository,
19+
private readonly Stopwatch $stopwatch
20+
) {
2221
parent::__construct();
23-
$this->managerRegistry = $managerRegistry;
24-
$this->stopwatch = $stopwatch;
2522
}
2623

27-
/**
28-
* @return SettingRepository
29-
*/
3024
public function getRepository(): SettingRepository
3125
{
32-
if (null === $this->repository) {
33-
$this->repository = $this->managerRegistry->getRepository(Setting::class);
34-
}
3526
return $this->repository;
3627
}
3728

@@ -72,9 +63,7 @@ public function getDocument(string $key): ?Document
7263
{
7364
try {
7465
$id = $this->getInt($key);
75-
return $this->managerRegistry
76-
->getRepository(Document::class)
77-
->findOneById($id);
66+
return $this->documentRepository->findOneById($id);
7867
} catch (\Exception $e) {
7968
return null;
8069
}

src/Cache/Clearer/FileClearer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
abstract class FileClearer implements ClearerInterface
88
{
99
protected ?string $output = null;
10-
protected string $cacheDir;
1110

12-
public function __construct(string $cacheDir)
11+
public function __construct(protected readonly string $cacheDir)
1312
{
14-
$this->cacheDir = $cacheDir;
1513
}
1614

1715
public function clear(): bool

src/Cache/Clearer/NodesSourcesUrlsCacheClearer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
final class NodesSourcesUrlsCacheClearer extends FileClearer
1010
{
11-
private CacheItemPoolInterface $cacheProvider;
12-
13-
public function __construct(CacheItemPoolInterface $cacheProvider)
11+
public function __construct(private readonly CacheItemPoolInterface $cacheProvider)
1412
{
1513
parent::__construct('');
16-
$this->cacheProvider = $cacheProvider;
1714
}
1815

1916
public function clear(): bool

src/Cache/CloudflareProxyCache.php

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,15 @@
66

77
final class CloudflareProxyCache
88
{
9-
protected string $name;
10-
protected string $zone;
11-
protected string $version;
12-
protected string $bearer;
13-
protected string $email;
14-
protected string $key;
15-
protected int $timeout;
16-
17-
/**
18-
* @param string $name
19-
* @param string $zone
20-
* @param string $version
21-
* @param string $bearer
22-
* @param string $email
23-
* @param string $key
24-
* @param int $timeout
25-
*/
26-
public function __construct(string $name, string $zone, string $version, string $bearer, string $email, string $key, int $timeout)
27-
{
28-
$this->name = $name;
29-
$this->zone = $zone;
30-
$this->version = $version;
31-
$this->bearer = $bearer;
32-
$this->email = $email;
33-
$this->key = $key;
34-
$this->timeout = $timeout;
9+
public function __construct(
10+
private readonly string $name,
11+
private readonly string $zone,
12+
private readonly string $version,
13+
private readonly string $bearer,
14+
private readonly string $email,
15+
private readonly string $key,
16+
private readonly int $timeout
17+
) {
3518
}
3619

3720
/**

src/Cache/ReverseProxyCache.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,12 @@
66

77
final class ReverseProxyCache
88
{
9-
protected string $name;
10-
protected string $host;
11-
protected string $domainName;
12-
protected int $timeout;
13-
14-
/**
15-
* @param string $name
16-
* @param string $host
17-
* @param string $domainName
18-
* @param int $timeout
19-
*/
20-
public function __construct(string $name, string $host, string $domainName, int $timeout)
21-
{
22-
$this->name = $name;
23-
$this->host = $host;
24-
$this->domainName = $domainName;
25-
$this->timeout = $timeout;
9+
public function __construct(
10+
private readonly string $name,
11+
private readonly string $host,
12+
private readonly string $domainName,
13+
private readonly int $timeout
14+
) {
2615
}
2716

2817
/**
@@ -48,4 +37,9 @@ public function getDomainName(): string
4837
{
4938
return $this->domainName;
5039
}
40+
41+
public function getTimeout(): int
42+
{
43+
return $this->timeout;
44+
}
5145
}

src/Cache/ReverseProxyCacheLocator.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@
66

77
final class ReverseProxyCacheLocator
88
{
9-
/**
10-
* @var ReverseProxyCache[]
11-
*/
12-
private array $frontends;
13-
private ?CloudflareProxyCache $cloudflareProxyCache;
14-
159
/**
1610
* @param ReverseProxyCache[] $frontends
1711
* @param CloudflareProxyCache|null $cloudflareProxyCache
1812
*/
19-
public function __construct(array $frontends, ?CloudflareProxyCache $cloudflareProxyCache = null)
20-
{
21-
$this->frontends = $frontends;
22-
$this->cloudflareProxyCache = $cloudflareProxyCache;
13+
public function __construct(
14+
private readonly array $frontends,
15+
private readonly ?CloudflareProxyCache $cloudflareProxyCache = null
16+
) {
2317
}
2418

2519
/**

src/Console/AppInstallCommand.php

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,23 @@
2121
use Symfony\Component\HttpFoundation\File\File;
2222
use Symfony\Component\Yaml\Yaml;
2323

24-
/**
25-
* Command line utils for managing themes from terminal.
26-
*/
2724
final class AppInstallCommand extends Command
2825
{
29-
protected SymfonyStyle $io;
26+
private SymfonyStyle $io;
3027
private bool $dryRun = false;
31-
protected string $projectDir;
32-
protected NodeTypesImporter $nodeTypesImporter;
33-
protected TagsImporter $tagsImporter;
34-
protected SettingsImporter $settingsImporter;
35-
protected RolesImporter $rolesImporter;
36-
protected GroupsImporter $groupsImporter;
37-
protected AttributeImporter $attributeImporter;
38-
protected ManagerRegistry $managerRegistry;
3928

4029
public function __construct(
41-
string $projectDir,
42-
ManagerRegistry $managerRegistry,
43-
NodeTypesImporter $nodeTypesImporter,
44-
TagsImporter $tagsImporter,
45-
SettingsImporter $settingsImporter,
46-
RolesImporter $rolesImporter,
47-
GroupsImporter $groupsImporter,
48-
AttributeImporter $attributeImporter,
49-
string $name = null
30+
private readonly string $projectDir,
31+
private readonly ManagerRegistry $managerRegistry,
32+
private readonly NodeTypesImporter $nodeTypesImporter,
33+
private readonly TagsImporter $tagsImporter,
34+
private readonly SettingsImporter $settingsImporter,
35+
private readonly RolesImporter $rolesImporter,
36+
private readonly GroupsImporter $groupsImporter,
37+
private readonly AttributeImporter $attributeImporter,
38+
?string $name = null
5039
) {
5140
parent::__construct($name);
52-
$this->projectDir = $projectDir;
53-
$this->nodeTypesImporter = $nodeTypesImporter;
54-
$this->tagsImporter = $tagsImporter;
55-
$this->settingsImporter = $settingsImporter;
56-
$this->rolesImporter = $rolesImporter;
57-
$this->groupsImporter = $groupsImporter;
58-
$this->attributeImporter = $attributeImporter;
59-
$this->managerRegistry = $managerRegistry;
6041
}
6142

6243
protected function configure(): void

src/Console/AppMigrateCommand.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use RZ\Roadiz\CoreBundle\Doctrine\SchemaUpdater;
88
use Symfony\Component\Console\Command\Command;
9-
use Symfony\Component\Console\Input\InputArgument;
109
use Symfony\Component\Console\Input\InputInterface;
1110
use Symfony\Component\Console\Input\InputOption;
1211
use Symfony\Component\Console\Output\OutputInterface;
@@ -16,14 +15,12 @@
1615

1716
final class AppMigrateCommand extends Command
1817
{
19-
protected string $projectDir;
20-
private SchemaUpdater $schemaUpdater;
21-
22-
public function __construct(SchemaUpdater $schemaUpdater, string $projectDir, ?string $name = null)
23-
{
18+
public function __construct(
19+
private readonly SchemaUpdater $schemaUpdater,
20+
private readonly string $projectDir,
21+
?string $name = null
22+
) {
2423
parent::__construct($name);
25-
$this->projectDir = $projectDir;
26-
$this->schemaUpdater = $schemaUpdater;
2724
}
2825

2926
protected function configure(): void

src/Console/CustomFormAnswerPurgeCommand.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@
1919

2020
final class CustomFormAnswerPurgeCommand extends Command
2121
{
22-
private ManagerRegistry $managerRegistry;
23-
private EventDispatcherInterface $eventDispatcher;
24-
private LoggerInterface $logger;
25-
2622
public function __construct(
27-
ManagerRegistry $managerRegistry,
28-
EventDispatcherInterface $eventDispatcher,
29-
LoggerInterface $logger,
23+
private readonly ManagerRegistry $managerRegistry,
24+
private readonly EventDispatcherInterface $eventDispatcher,
25+
private readonly LoggerInterface $logger,
3026
string $name = null
3127
) {
3228
parent::__construct($name);
33-
$this->managerRegistry = $managerRegistry;
34-
$this->eventDispatcher = $eventDispatcher;
35-
$this->logger = $logger;
3629
}
3730

3831
protected function configure(): void

0 commit comments

Comments
 (0)