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
02:35
created

checkForTemplatesAndUniquePagesNotDistinct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
1
<?php
2
3
namespace Backpack\PageManager\app;
4
5
6
trait TraitReflections
7
{
8
9
    public function checkForTemplatesAndUniquePagesNotDistinct()
10
    {
11
        if (config('backpack.pagemanager.page_model_class') != config('backpack.pagemanager.unique_page_model_class')) {
12
            return;
13
        }
14
15
        $uniquePages = collect($this->getUniquePages())->pluck('name');
16
        $templates = collect($this->getTemplates())->pluck('name');
17
18
        if ($uniquePages->intersect($templates)->isNotEmpty()) {
19
            throw new \Exception('Templates and unique pages should 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 134 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...
20
        }
21
    }
22
23
    /**
24
     * Get all defined unique pages
25
     */
26
    public function getUniquePages()
27
    {
28
        $pages_trait = new \ReflectionClass('App\UniquePages');
29
        $pages = $pages_trait->getMethods(\ReflectionMethod::IS_PRIVATE);
30
31
        return $pages;
32
    }
33
34
    /**
35
     * Get all defined templates.
36
     */
37
    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...
38
    {
39
        $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...
40
41
        $templates_trait = new \ReflectionClass('App\PageTemplates');
42
        $templates = $templates_trait->getMethods(\ReflectionMethod::IS_PRIVATE);
43
44
        if (! count($templates)) {
45
            abort(503, trans('backpack::pagemanager.template_not_found'));
46
        }
47
48
        return $templates;
49
    }
50
}