Skip to content

Commit 37676b0

Browse files
committed
constr prop promotion
1 parent 39e8e57 commit 37676b0

File tree

2 files changed

+27
-54
lines changed

2 files changed

+27
-54
lines changed

src/EventRegistry.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
class EventRegistry
4444
{
4545
// list of *known* events to always include (if they exist)
46-
private static $newEventsMap = [
46+
private static array $newEventsMap = [
4747
'kernel.exception' => ExceptionEvent::class,
4848
'kernel.request' => RequestEvent::class,
4949
'kernel.response' => ResponseEvent::class,
@@ -53,7 +53,7 @@ class EventRegistry
5353
'kernel.terminate' => TerminateEvent::class,
5454
];
5555

56-
private static $eventsMap = [
56+
private static array $eventsMap = [
5757
'console.command' => ConsoleCommandEvent::class,
5858
'console.terminate' => ConsoleTerminateEvent::class,
5959
'console.error' => ConsoleErrorEvent::class,
@@ -71,12 +71,9 @@ class EventRegistry
7171
'security.switch_user' => SwitchUserEvent::class,
7272
];
7373

74-
private $eventDispatcher;
75-
76-
public function __construct(EventDispatcherInterface $eventDispatcher)
77-
{
78-
$this->eventDispatcher = $eventDispatcher;
79-
74+
public function __construct(
75+
private EventDispatcherInterface $eventDispatcher,
76+
) {
8077
// Loop through the new event classes
8178
foreach (self::$newEventsMap as $eventName => $newEventClass) {
8279
// Check if the new event classes exist, if so replace the old one with the new.

src/FileManager.php

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,15 @@
2525
*/
2626
class FileManager
2727
{
28-
private $fs;
29-
private $autoloaderUtil;
30-
private $makerFileLinkFormatter;
31-
private $rootDirectory;
32-
/** @var SymfonyStyle */
33-
private $io;
34-
private $twigDefaultPath;
28+
private ?SymfonyStyle $io = null;
3529

3630
public function __construct(
37-
Filesystem $fs,
38-
AutoloaderUtil $autoloaderUtil,
39-
MakerFileLinkFormatter $makerFileLinkFormatter,
40-
string $rootDirectory,
41-
string $twigDefaultPath = null,
31+
private Filesystem $fs,
32+
private AutoloaderUtil $autoloaderUtil,
33+
private MakerFileLinkFormatter $makerFileLinkFormatter,
34+
private string $rootDirectory,
35+
private ?string $twigDefaultPath = null,
4236
) {
43-
// move FileManagerTest stuff
44-
// update EntityRegeneratorTest to mock the autoloader
45-
$this->fs = $fs;
46-
$this->autoloaderUtil = $autoloaderUtil;
47-
$this->makerFileLinkFormatter = $makerFileLinkFormatter;
4837
$this->rootDirectory = rtrim($this->realPath($this->normalizeSlashes($rootDirectory)), '/');
4938
$this->twigDefaultPath = $twigDefaultPath ? rtrim($this->relativizePath($twigDefaultPath), '/') : null;
5039
}
@@ -77,13 +66,11 @@ public function dumpFile(string $filename, string $content): void
7766
$this->fs->dumpFile($absolutePath, $content);
7867
$relativePath = $this->relativizePath($filename);
7968

80-
if ($this->io) {
81-
$this->io->comment(sprintf(
82-
'%s: %s',
83-
$comment,
84-
$this->makerFileLinkFormatter->makeLinkedPath($absolutePath, $relativePath)
85-
));
86-
}
69+
$this->io?->comment(sprintf(
70+
'%s: %s',
71+
$comment,
72+
$this->makerFileLinkFormatter->makeLinkedPath($absolutePath, $relativePath)
73+
));
8774
}
8875

8976
public function fileExists($path): bool
@@ -94,24 +81,22 @@ public function fileExists($path): bool
9481
/**
9582
* Attempts to make the path relative to the root directory.
9683
*
97-
* @param string $absolutePath
98-
*
9984
* @throws \Exception
10085
*/
101-
public function relativizePath($absolutePath): string
86+
public function relativizePath(string $absolutePath): string
10287
{
10388
$absolutePath = $this->normalizeSlashes($absolutePath);
10489

10590
// see if the path is even in the root
106-
if (false === strpos($absolutePath, $this->rootDirectory)) {
91+
if (!str_contains($absolutePath, $this->rootDirectory)) {
10792
return $absolutePath;
10893
}
10994

11095
$absolutePath = $this->realPath($absolutePath);
11196

11297
// str_replace but only the first occurrence
11398
$relativePath = ltrim(implode('', explode($this->rootDirectory, $absolutePath, 2)), '/');
114-
if (0 === strpos($relativePath, './')) {
99+
if (str_starts_with($relativePath, './')) {
115100
$relativePath = substr($relativePath, 2);
116101
}
117102

@@ -127,22 +112,17 @@ public function getFileContents(string $path): string
127112
return file_get_contents($this->absolutizePath($path));
128113
}
129114

130-
public function createFinder(string $in): Finder
131-
{
132-
$finder = new Finder();
133-
$finder->in($this->absolutizePath($in));
134-
135-
return $finder;
136-
}
137-
138115
public function isPathInVendor(string $path): bool
139116
{
140-
return 0 === strpos($this->normalizeSlashes($path), $this->normalizeSlashes($this->rootDirectory.'/vendor/'));
117+
return str_starts_with(
118+
$this->normalizeSlashes($path),
119+
$this->normalizeSlashes($this->rootDirectory.'/vendor/')
120+
);
141121
}
142122

143123
public function absolutizePath($path): string
144124
{
145-
if (0 === strpos($path, '/')) {
125+
if (str_starts_with($path, '/')) {
146126
return $path;
147127
}
148128

@@ -190,10 +170,8 @@ public function getPathForTemplate(string $filename): string
190170

191171
/**
192172
* Resolve '../' in paths (like real_path), but for non-existent files.
193-
*
194-
* @param string $absolutePath
195173
*/
196-
private function realPath($absolutePath): string
174+
private function realPath(string $absolutePath): string
197175
{
198176
$finalParts = [];
199177
$currentIndex = -1;
@@ -219,12 +197,10 @@ private function realPath($absolutePath): string
219197
$finalPath = implode('/', $finalParts);
220198
// Normalize: // => /
221199
// Normalize: /./ => /
222-
$finalPath = str_replace(['//', '/./'], '/', $finalPath);
223-
224-
return $finalPath;
200+
return str_replace(['//', '/./'], '/', $finalPath);
225201
}
226202

227-
private function normalizeSlashes(string $path)
203+
private function normalizeSlashes(string $path): string
228204
{
229205
return str_replace('\\', '/', $path);
230206
}

0 commit comments

Comments
 (0)