These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\SchemaOrg\Generator\Parser\Tasks; |
||
4 | |||
5 | use Symfony\Component\DomCrawler\Crawler; |
||
6 | |||
7 | abstract class Task |
||
8 | { |
||
9 | /** @string */ |
||
10 | protected $definition; |
||
11 | |||
12 | public function __construct(string $definition) |
||
13 | { |
||
14 | $this->definition = $definition; |
||
15 | } |
||
16 | |||
17 | public static function fromCrawler(Crawler $crawler): self |
||
18 | { |
||
19 | $node = $crawler->getNode(0); |
||
20 | $html = $node->ownerDocument->saveHTML($node); |
||
21 | |||
22 | return new static($html); |
||
23 | } |
||
24 | |||
25 | protected function getText(Crawler $node, string $selector = null): string |
||
26 | { |
||
27 | if ($selector) { |
||
0 ignored issues
–
show
|
|||
28 | $node = $node->filter($selector)->first(); |
||
29 | } |
||
30 | |||
31 | if ($node->count() === 0) { |
||
32 | return ''; |
||
33 | } |
||
34 | |||
35 | return trim($node->text()); |
||
36 | } |
||
37 | |||
38 | protected function getAttribute(Crawler $node, string $attribute): string |
||
39 | { |
||
40 | if ($node->count() === 0) { |
||
41 | return ''; |
||
42 | } |
||
43 | |||
44 | return $node->filter("[{$attribute}]")->attr($attribute) ?? ''; |
||
45 | } |
||
46 | } |
||
47 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: