These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Highlighter |
||
4 | * |
||
5 | * Copyright (C) 2016, Some right reserved. |
||
6 | * |
||
7 | * @author Kacper "Kadet" Donat <[email protected]> |
||
8 | * |
||
9 | * Contact with author: |
||
10 | * Xmpp: [email protected] |
||
11 | * E-mail: [email protected] |
||
12 | * |
||
13 | * From Kadet with love. |
||
14 | */ |
||
15 | |||
16 | namespace Kadet\Highlighter\Language; |
||
17 | |||
18 | |||
19 | use Kadet\Highlighter\Matcher\RegexMatcher; |
||
20 | use Kadet\Highlighter\Parser\Rule; |
||
21 | |||
22 | class Xaml extends Xml |
||
23 | { |
||
24 | public function setupRules() |
||
25 | { |
||
26 | parent::setupRules(); |
||
27 | |||
28 | $attribute = $this->rules->rule('symbol.attribute'); |
||
29 | $tag = $this->rules->rule('symbol.tag'); |
||
30 | |||
31 | $this->rules->remove('symbol.attribute'); |
||
32 | $this->rules->remove('symbol.tag'); |
||
33 | |||
34 | $this->rules->add('variable', $attribute); |
||
35 | $this->rules->add('symbol.class', $tag); |
||
36 | $this->rules->add('variable.property', new Rule(new RegexMatcher('/[\w-]+\.([\w-]+)/'), [ |
||
37 | 'context' => ['*tag', '*expression', '!string'] |
||
38 | ])); |
||
39 | |||
40 | $this->rules->add('expression', new Rule(new RegexMatcher('/=["\']?(?P<expression>\{(?>(?:(?&expression)|[^{}]*)*)\})/'), [ |
||
41 | 'context' => ['tag.open'] |
||
42 | ])); |
||
43 | } |
||
44 | |||
45 | public static function getMetadata() |
||
46 | { |
||
47 | return [ |
||
0 ignored issues
–
show
|
|||
48 | 'name' => ['xaml'], |
||
49 | 'mime' => [], |
||
50 | 'extension' => ['*.xaml'] |
||
51 | ]; |
||
52 | } |
||
53 | } |
||
54 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.