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.

Time   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 2
cbo 1
dl 0
loc 46
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 10 2
A getInputSpecification() 0 19 1
1
<?php
2
/*
3
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
5
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
6
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
7
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
8
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
 */
10
11
namespace MpaCustomDoctrineHydrator\Form\Element;
12
13
use Zend\Filter\StringTrim;
14
15
class Time extends DateTime
16
{
17
    /**
18
     * Accepted options for DateTime:
19
     * - format: A \DateTime compatible string
20
     *
21
     * @param  array|\Traversable $options
22
     * @return \DateTime
23
     */
24 1
    public function setOptions($options)
25
    {
26 1
        parent::setOptions($options);
27
28 1
        if (isset($this->options['time_format'])) {
29 1
            $this->setFormat($this->options['time_format']);
30
        }
31
32 1
        return $this;
33
    }
34
35
    /**
36
     * Provide default input rules for this element
37
     * Attaches default validators for the Date input.
38
     *
39
     * @return array
40
     */
41 5
    public function getInputSpecification()
42
    {
43
        return [
0 ignored issues
show
Best Practice introduced by
The expression return array('name' => $...->getDateValidator())); seems to be an array, but some of its elements' types (array[]) are incompatible with the return type of the parent method MpaCustomDoctrineHydrato...::getInputSpecification of type array<string,string|inte...|Zend\Validator\Date[]>.

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 new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return '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...
44 5
            'name'       => $this->getName(),
45
            'required'   => true,
46
            'filters'    => [
47
                ['name' => StringTrim::class],
48
                [
49 5
                    'name'    => 'MpaCustomDoctrineHydrator\Filter\TimeToDateTime',
50
                    'options' => [
51 5
                        'time_format' => $this->getFormat(),
52
                    ]
53
                ],
54
            ],
55
            'validators' => [
56 5
                $this->getDateValidator()
57
            ],
58
        ];
59
    }
60
}
61