These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @package elemental |
||
5 | */ |
||
6 | class ElementContent extends BaseElement |
||
0 ignored issues
–
show
|
|||
7 | { |
||
8 | |||
9 | private static $db = array( |
||
0 ignored issues
–
show
|
|||
10 | 'HTML' => 'HTMLText', |
||
11 | 'Style' => 'Varchar' |
||
12 | ); |
||
13 | |||
14 | private static $styles = array(); |
||
0 ignored issues
–
show
|
|||
15 | |||
16 | private static $title = "Content Block"; |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | private static $description = "Block of text with heading, blockquote, list and paragraph styles"; |
||
0 ignored issues
–
show
|
|||
19 | |||
20 | public function getCMSFields() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
21 | { |
||
22 | $styles = $this->config()->get('styles'); |
||
23 | |||
24 | if (count($styles) > 0) { |
||
25 | $this->beforeUpdateCMSFields(function ($fields) use ($styles) { |
||
26 | $fields->addFieldsToTab('Root.Main', new HtmlEditorField('HTML', 'Content')); |
||
27 | $fields->addFieldsToTab('Root.Main', $styles = new DropdownField('Style', 'Style', $styles)); |
||
0 ignored issues
–
show
Consider using a different name than the imported variable
$styles , or did you forget to import by reference?
It seems like you are assigning to a variable which was imported through a For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope. Change not visible in outer-scope$x = 1;
$callable = function() use ($x) {
$x = 2; // Not visible in outer scope. If you would like this, how
// about using a different variable name than $x?
};
$callable();
var_dump($x); // integer(1)
Change visible in outer-scope$x = 1;
$callable = function() use (&$x) {
$x = 2;
};
$callable();
var_dump($x); // integer(2)
Loading history...
|
|||
28 | |||
29 | $styles->setEmptyString('Select a custom style..'); |
||
30 | }); |
||
31 | } else { |
||
32 | $this->beforeUpdateCMSFields(function ($fields) { |
||
33 | $fields->removeByName('Style'); |
||
34 | }); |
||
35 | } |
||
36 | |||
37 | $fields = parent::getCMSFields(); |
||
38 | |||
39 | if ($this->isEndofLine('ElementContent') && $this->hasExtension('VersionViewerDataObject')) { |
||
40 | $fields = $this->addVersionViewer($fields, $this); |
||
0 ignored issues
–
show
The method
addVersionViewer does not exist on object<ElementContent> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
41 | } |
||
42 | |||
43 | return $fields; |
||
44 | } |
||
45 | |||
46 | public function getCssStyle() |
||
47 | { |
||
48 | $styles = $this->config()->get('styles'); |
||
49 | $style = $this->Style; |
||
0 ignored issues
–
show
The property
Style does not exist on object<ElementContent> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
50 | |||
51 | if (isset($styles[$style])) { |
||
52 | return strtolower($styles[$style]); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.