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

Completed
Pull Request — master (#61)
by Oliver
01:31
created

TraitReflections::getUniquePageNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Backpack\PageManager\app;
4
5
use Illuminate\Support\Collection;
6
7
trait TraitReflections
8
{
9
    /**
10
     * Check for equal named templates and unique pages.
11
     *
12
     * As the method name of a unique page will also be the template name in the database,
13
     * we must ensure that there are not any equal names defined.
14
     * If different Models (and so different tables in the database) are used, this condition must not hold any more.
15
     *
16
     * @throws \Exception
17
     */
18
    public function checkForTemplatesAndUniquePagesNotDistinct()
19
    {
20
        if (config('backpack.pagemanager.page_model_class') !== config('backpack.pagemanager.unique_page_model_class')) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
21
            return;
22
        }
23
24
        $uniquePages = $this->getUniquePageNames();
25
        $templates = $this->getTemplateNames();
26
27
        if ($uniquePages->intersect($templates)->isNotEmpty()) {
28
            throw new \Exception('Templates and unique pages must not have the same function names when same model class is used.');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
29
        }
30
    }
31
32
    /**
33
     * Get all defined unique pages.
34
     *
35
     * @return Collection
36
     */
37
    public function getUniquePages()
38
    {
39
        $pages_trait = new \ReflectionClass('App\UniquePages');
40
        $pages = $pages_trait->getMethods(\ReflectionMethod::IS_PRIVATE);
41
42
        return collect($pages);
43
    }
44
45
    /**
46
     * Get all defined unique page names.
47
     *
48
     * @return Collection
49
     */
50
    public function getUniquePageNames()
51
    {
52
        return $this->getUniquePages()->pluck('name');
53
    }
54
55
    /**
56
     * Get the page names keyed with slugs.
57
     *
58
     * @return Collection
59
     */
60
    public function getUniqueSlugs()
61
    {
62
        return $this->getUniquePageNames()->mapWithKeys(function ($name) {
63
            return [str_slug($name) => $name];
64
        });
65
    }
66
67
    /**
68
     * Get all defined templates.
69
     *
70
     * @return Collection
71
     */
72
    public function getTemplates($template_name = false)
0 ignored issues
show
Unused Code introduced by
The parameter $template_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style Naming introduced by
The parameter $template_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
73
    {
74
        $templates_array = [];
0 ignored issues
show
Unused Code introduced by
$templates_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
75
76
        $templates_trait = new \ReflectionClass('App\PageTemplates');
77
        $templates = $templates_trait->getMethods(\ReflectionMethod::IS_PRIVATE);
78
79
        if (! count($templates)) {
80
            abort(503, trans('backpack::pagemanager.template_not_found'));
81
        }
82
83
        return collect($templates);
84
    }
85
86
    /**
87
     * Get all defined template names.
88
     *
89
     * @return Collection
90
     */
91
    public function getTemplateNames()
92
    {
93
        return $this->getTemplates()->pluck('name');
94
    }
95
}
96