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.
Completed
Push — master ( 50e57a...1d39d2 )
by Florian
03:06
created

Query::__set()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Stinger Entity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\EntitySearchBundle\Model;
13
14
class Query {
15
16
	/**
17
	 *
18
	 * @var string
19
	 */
20
	private $term;
21
22
	/**
23
	 *
24
	 * @var string[string]
25
	 */
26
	private $facets = array();
27
28
	/**
29
	 *
30
	 * @var string[]
31
	 */
32
	private $usedFacets = null;
33
34
	/**
35
	 *
36
	 * @param string $term        	
37
	 * @param string[string] $facets        	
0 ignored issues
show
Documentation introduced by
The doc-type string[string] could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
38
	 * @param string[] $usedFacets        	
39
	 */
40
	public function __construct($term = null, array $facets = array(), $usedFacets = null) {
41
		$this->term = $term;
42
		$this->facets = $facets;
43
		$this->usedFacets = $usedFacets;
0 ignored issues
show
Documentation Bug introduced by
It seems like $usedFacets can be null. However, the property $usedFacets is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
44
	}
45
46
	/**
47
	 * Get the search term
48
	 *
49
	 * @return string Returns the search term
50
	 */
51
	public function getSearchTerm() {
52
		return $this->term;
53
	}
54
55
	/**
56
	 *
57
	 * @return string[string]
0 ignored issues
show
Documentation introduced by
The doc-type string[string] could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
58
	 */
59
	public function getFacets() {
60
		return $this->facets;
61
	}
62
63
	/**
64
	 *
65
	 * @return string[]
66
	 */
67
	public function getUsedFacets() {
68
		return $this->usedFacets;
69
	}
70
71
	public function setSearchTerm($term) {
72
		$this->term = $term;
73
		return $this;
74
	}
75
76
	public function setFacets($facets) {
77
		$this->facets = $facets;
78
		return $this;
79
	}
80
81
	public function setUsedFacets($usedFacets) {
82
		$this->usedFacets = $usedFacets;
83
		return $this;
84
	}
85
86
	/**
87
	 *
88
	 * @param string $name
89
	 *        	Name of the property to fetch
90
	 * @return \Pec\Bundle\MtuDvpBundle\Entity\TestRiskValue
91
	 */
92
	public function __get($name) {
93
		if(strrpos($name, 'facet_', -strlen($name)) !== false) {
94
			$facetname = substr($name, 6);
95
			
96
			if(isset($this->facets[$facetname])) {
97
				return $this->facets[$facetname];
98
			}
99
			return array();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(); (array) is incompatible with the return type documented by StingerSoft\EntitySearchBundle\Model\Query::__get of type Pec\Bundle\MtuDvpBundle\Entity\TestRiskValue.

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...
100
		}
101
	}
102
103
	/**
104
	 *
105
	 * @param string $name
106
	 *        	Name of the property to set
107
	 * @param mixed $value
108
	 *        	The value of the property
109
	 */
110
	public function __set($name, $value) {
111
		if(strrpos($name, 'facet_', -strlen($name)) !== false) {
112
			$facetname = substr($name, 6);
113
			
114
			if(isset($this->facets[$facetname])) {
115
				$this->facets[$facetname] = array();
116
			}
117
			$this->facets[$facetname] = $value;
118
		}
119
	}
120
121
	/**
122
	 * Checks whether the given property is set or not
123
	 *
124
	 * @param string $name        	
125
	 * @return boolean
126
	 */
127
	public function __isset($name) {
128
		if(strrpos($name, 'facet_', -strlen($name)) !== false) {
129
			return true;
130
		}
131
		
132
		return false;
133
	}
134
}