GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExportVariable   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 9
Bugs 3 Features 4
Metric Value
wmc 7
c 9
b 3
f 4
lcom 0
cbo 0
dl 0
loc 80
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getGroups() 0 11 2
A getTemplate() 0 11 2
A getFields() 0 18 2
A customTableRow() 0 5 1
1
<?php
2
3
namespace Craft;
4
5
/**
6
 * Export variable.
7
 *
8
 * Acts as a bridge between services and templates.
9
 *
10
 * @author    Bob Olde Hampsink <[email protected]>
11
 * @copyright Copyright (c) 2015, Bob Olde Hampsink
12
 * @license   MIT
13
 *
14
 * @link      http://github.com/boboldehampsink
15
 */
16
class ExportVariable
17
{
18
    /**
19
     * Return "groups" (section, groups, etc.).
20
     *
21
     * @param string $elementType
22
     *
23
     * @return array|bool
24
     */
25
    public function getGroups($elementType)
26
    {
27
        // Check if elementtype can be imported
28
        if ($service = craft()->export->getService($elementType)) {
29
30
            // Return "groups" (section, groups, etc.)
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
            return $service->getGroups();
32
        }
33
34
        return false;
35
    }
36
37
    /**
38
     * Get template for service.
39
     *
40
     * @param string $elementType
41
     *
42
     * @return array|bool
43
     */
44
    public function getTemplate($elementType)
45
    {
46
        // Check if elementtype can be imported
47
        if ($service = craft()->export->getService($elementType)) {
48
49
            // Return template
50
            return $service->getTemplate();
51
        }
52
53
        return false;
54
    }
55
56
    /**
57
     * Get fields of elementType.
58
     *
59
     * @param string $elementType
60
     * @param bool   $reset
61
     *
62
     * @return array
63
     */
64
    public function getFields($elementType, $reset)
65
    {
66
        // Get export vars
67
        $export = craft()->request->getParam('export');
68
69
        // Unset non-map settings
70
        unset($export['limit'], $export['offset']);
71
        ksort($export);
72
73
        // Check if elementtype can be imported
74
        if ($service = craft()->export->getService($elementType)) {
75
76
            // Return fields of elementType
77
            return $service->getFields($export, $reset);
78
        }
79
80
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Craft\ExportVariable::getFields of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
81
    }
82
83
    /**
84
     * Get path to fieldtype's custom table row template.
85
     *
86
     * @param string $fieldHandle
87
     *
88
     * @return string
89
     */
90
    public function customTableRow($fieldHandle)
91
    {
92
        // Return custom <tr> for template
93
        return craft()->export->getCustomTableRow($fieldHandle);
94
    }
95
}
96