Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — add-update-command ( 52996a...7d33d9 )
by Pedro
14:43
created

filterCrudControllerPaths()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
nc 6
nop 2
dl 0
loc 27
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Console\Commands\Upgrade\v7\Concerns;
4
5
use Backpack\CRUD\app\Console\Commands\Upgrade\UpgradeContext;
6
7
/**
8
 * @mixin \Backpack\CRUD\app\Console\Commands\Upgrade\Step
9
 */
10
trait InteractsWithCrudControllers
11
{
12
    /**
13
     * Filter a list of file paths to those that look like CrudControllers and optionally validate contents.
14
     */
15
    protected function filterCrudControllerPaths(array $paths, ?callable $contentsValidator = null): array
16
    {
17
        if (empty($paths)) {
18
            return [];
19
        }
20
21
        $filtered = [];
22
23
        foreach ($paths as $path) {
24
            if (! $this->isCrudControllerPath($path)) {
25
                continue;
26
            }
27
28
            $contents = $this->context()->readFile($path);
29
30
            if ($contents === null) {
31
                continue;
32
            }
33
34
            if ($contentsValidator !== null && $contentsValidator($contents, $path) !== true) {
35
                continue;
36
            }
37
38
            $filtered[] = $path;
39
        }
40
41
        return $filtered;
42
    }
43
44
    /**
45
     * Build a short list of preview lines for the provided paths.
46
     */
47
    protected function previewLines(array $paths, int $limit = 10, ?callable $formatter = null): array
48
    {
49
        if (empty($paths)) {
50
            return [];
51
        }
52
53
        $formatter ??= static fn (string $path): string => "- {$path}";
54
55
        $preview = array_slice($paths, 0, $limit);
56
        $details = array_map($formatter, $preview);
57
58
        $remaining = count($paths) - count($preview);
59
60
        if ($remaining > 0) {
61
            $details[] = sprintf('… %d more occurrence(s) omitted.', $remaining);
62
        }
63
64
        return $details;
65
    }
66
67
    protected function isCrudControllerPath(string $path): bool
68
    {
69
        return str_contains($path, 'CrudController');
70
    }
71
72
    abstract protected function context(): UpgradeContext;
73
}
74