Skip to content

Commit 8a432a0

Browse files
committed
cs
1 parent f67eb85 commit 8a432a0

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

ncs.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/**
4+
* Rules for Nette Coding Standard
5+
* https://github.com/nette/coding-standard
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
return [
11+
// RobotLoader.php
12+
'Nette/statement_indentation' => false,
13+
];

src/RobotLoader/RobotLoader.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function addDirectory(...$paths): self
148148
trigger_error(__METHOD__ . '() use variadics ...$paths to add an array of paths.', E_USER_WARNING);
149149
$paths = $paths[0];
150150
}
151+
151152
$this->scanPaths = array_merge($this->scanPaths, $paths);
152153
return $this;
153154
}
@@ -170,6 +171,7 @@ public function excludeDirectory(...$paths): self
170171
trigger_error(__METHOD__ . '() use variadics ...$paths to add an array of paths.', E_USER_WARNING);
171172
$paths = $paths[0];
172173
}
174+
173175
$this->excludeDirs = array_merge($this->excludeDirs, $paths);
174176
return $this;
175177
}
@@ -185,6 +187,7 @@ public function getIndexedClasses(): array
185187
foreach ($this->classes as $class => [$file]) {
186188
$res[$class] = $file;
187189
}
190+
188191
return $res;
189192
}
190193

@@ -228,6 +231,7 @@ private function refreshClasses(): void
228231
$files[$file] = $mtime;
229232
$classes[$file][] = $class;
230233
}
234+
231235
$this->classes = $this->emptyFiles = [];
232236

233237
foreach ($this->scanPaths as $path) {
@@ -253,6 +257,7 @@ private function refreshClasses(): void
253257
if (isset($this->classes[$class])) {
254258
throw new Nette\InvalidStateException("Ambiguous class $class resolution; defined in {$this->classes[$class][0]} and in $file.");
255259
}
260+
256261
$this->classes[$class] = [$file, $mtime];
257262
unset($this->missingClasses[$class]);
258263
}
@@ -270,12 +275,14 @@ private function createFileIterator(string $dir): Nette\Utils\Finder
270275
if (!is_dir($dir)) {
271276
throw new Nette\IOException("File or directory '$dir' not found.");
272277
}
278+
273279
$dir = realpath($dir) ?: $dir; // realpath does not work in phar
274280

275281
if (is_string($ignoreDirs = $this->ignoreDirs)) {
276282
trigger_error(self::class . ': $ignoreDirs must be an array.', E_USER_WARNING);
277283
$ignoreDirs = preg_split('#[,\s]+#', $ignoreDirs);
278284
}
285+
279286
$disallow = [];
280287
foreach (array_merge($ignoreDirs, $this->excludeDirs) as $item) {
281288
if ($item = realpath($item)) {
@@ -300,6 +307,7 @@ private function createFileIterator(string $dir): Nette\Utils\Finder
300307
if ($dir->getRealPath() === false) {
301308
return true;
302309
}
310+
303311
$path = str_replace('\\', '/', $dir->getRealPath());
304312
if (is_file("$path/netterobots.txt")) {
305313
foreach (file("$path/netterobots.txt") as $s) {
@@ -308,6 +316,7 @@ private function createFileIterator(string $dir): Nette\Utils\Finder
308316
}
309317
}
310318
}
319+
311320
return !isset($disallow[$path]);
312321
});
313322

@@ -333,9 +342,11 @@ private function updateFile(string $file): void
333342
$this->updateFile($prevFile);
334343
[$prevFile] = $this->classes[$class] ?? null;
335344
}
345+
336346
if (isset($prevFile)) {
337347
throw new Nette\InvalidStateException("Ambiguous class $class resolution; defined in $prevFile and in $file.");
338348
}
349+
339350
$this->classes[$class] = [$file, filemtime($file)];
340351
}
341352
}
@@ -362,6 +373,7 @@ private function scanPhp(string $file): array
362373
$rp->setValue($e, $file);
363374
throw $e;
364375
}
376+
365377
$tokens = [];
366378
}
367379

@@ -380,6 +392,7 @@ private function scanPhp(string $file): array
380392
if ($expected) {
381393
$name .= $token[1];
382394
}
395+
383396
continue 2;
384397

385398
case T_NAMESPACE:
@@ -406,6 +419,7 @@ private function scanPhp(string $file): array
406419
} elseif ($name && $level === $minLevel) {
407420
$classes[] = $namespace . $name;
408421
}
422+
409423
$expected = null;
410424
}
411425

@@ -415,6 +429,7 @@ private function scanPhp(string $file): array
415429
$level--;
416430
}
417431
}
432+
418433
return $classes;
419434
}
420435

@@ -451,6 +466,7 @@ private function loadCache(): void
451466
if ($this->cacheLoaded) {
452467
return;
453468
}
469+
454470
$this->cacheLoaded = true;
455471

456472
$file = $this->getCacheFile();
@@ -472,6 +488,7 @@ private function loadCache(): void
472488
if ($lock) {
473489
flock($lock, LOCK_UN); // release shared lock so we can get exclusive
474490
}
491+
475492
$lock = $this->acquireLock("$file.lock", LOCK_EX);
476493

477494
// while waiting for exclusive lock, someone might have already created the cache
@@ -506,6 +523,7 @@ private function saveCache($lock = null): void
506523
@unlink("$file.tmp"); // @ file may not exist
507524
throw new \RuntimeException("Unable to create '$file'.");
508525
}
526+
509527
if (function_exists('opcache_invalidate')) {
510528
@opcache_invalidate($file, true); // @ can be restricted
511529
}
@@ -521,6 +539,7 @@ private function acquireLock(string $file, int $mode)
521539
} elseif (!@flock($handle, $mode)) { // @ is escalated to exception
522540
throw new \RuntimeException('Unable to acquire ' . ($mode & LOCK_EX ? 'exclusive' : 'shared') . " lock on file '$file'. " . error_get_last()['message']);
523541
}
542+
524543
return $handle;
525544
}
526545

@@ -530,6 +549,7 @@ private function getCacheFile(): string
530549
if (!$this->tempDirectory) {
531550
throw new \LogicException('Set path to temporary directory using setTempDirectory().');
532551
}
552+
533553
return $this->tempDirectory . '/' . md5(serialize($this->getCacheKey())) . '.php';
534554
}
535555

tests/Loaders/files/namespaces1.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace
6-
{
5+
namespace {
76
class TestClass
87
{
98
}

0 commit comments

Comments
 (0)