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 | * This file is part of the league/commonmark package. |
||
5 | * |
||
6 | * (c) Colin O'Dell <[email protected]> |
||
7 | * |
||
8 | * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) |
||
9 | * - (c) John MacFarlane |
||
10 | * |
||
11 | * For the full copyright and license information, please view the LICENSE |
||
12 | * file that was distributed with this source code. |
||
13 | */ |
||
14 | |||
15 | namespace League\CommonMark; |
||
16 | |||
17 | use League\CommonMark\Block\Element\AbstractBlock; |
||
18 | use League\CommonMark\Delimiter\DelimiterStack; |
||
19 | use League\CommonMark\Reference\ReferenceMap; |
||
20 | |||
21 | class InlineParserContext |
||
22 | { |
||
23 | private $container; |
||
24 | private $referenceMap; |
||
25 | private $cursor; |
||
26 | private $delimiterStack; |
||
27 | |||
28 | 1752 | public function __construct(AbstractBlock $container, ReferenceMap $referenceMap) |
|
29 | { |
||
30 | 1752 | $this->referenceMap = $referenceMap; |
|
31 | 1752 | $this->container = $container; |
|
32 | 1752 | $this->cursor = new Cursor(\trim($container->getStringContent())); |
|
0 ignored issues
–
show
|
|||
33 | 1752 | $this->delimiterStack = new DelimiterStack(); |
|
34 | 1752 | } |
|
35 | |||
36 | /** |
||
37 | * @return AbstractBlock |
||
38 | */ |
||
39 | 1293 | public function getContainer(): AbstractBlock |
|
40 | { |
||
41 | 1293 | return $this->container; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return ReferenceMap |
||
46 | */ |
||
47 | 429 | public function getReferenceMap(): ReferenceMap |
|
48 | { |
||
49 | 429 | return $this->referenceMap; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return Cursor |
||
54 | */ |
||
55 | 1752 | public function getCursor(): Cursor |
|
56 | { |
||
57 | 1752 | return $this->cursor; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return DelimiterStack |
||
62 | */ |
||
63 | 1743 | public function getDelimiterStack(): DelimiterStack |
|
64 | { |
||
65 | 1743 | return $this->delimiterStack; |
|
66 | } |
||
67 | } |
||
68 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: