These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | use Spatie\Crawler\Crawler; |
||
4 | use Spatie\Crawler\CrawlInternalUrls; |
||
5 | use Spatie\Crawler\CrawlObserver; |
||
6 | use Psr\Http\Message\UriInterface; |
||
7 | |||
8 | include "vendor/autoload.php"; |
||
9 | |||
10 | $observer = new class implements CrawlObserver |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
11 | { |
||
12 | /** |
||
13 | * Called when the crawler will crawl the url. |
||
14 | * |
||
15 | * @param \Psr\Http\Message\UriInterface $url |
||
16 | */ |
||
17 | public function willCrawl(UriInterface $url) |
||
18 | { |
||
19 | |||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Called when the crawler has crawled the given url. |
||
24 | * |
||
25 | * @param \Psr\Http\Message\UriInterface $url |
||
26 | * @param \Psr\Http\Message\ResponseInterface|null $response |
||
27 | * @param \Psr\Http\Message\UriInterface|null $foundOnUrl |
||
28 | */ |
||
29 | public function hasBeenCrawled(UriInterface $url, $response, ?UriInterface $foundOnUrl = null) |
||
30 | { |
||
31 | |||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Called when the crawl has ended. |
||
36 | */ |
||
37 | public function finishedCrawling() |
||
38 | { |
||
39 | |||
40 | } |
||
41 | }; |
||
42 | |||
43 | |||
44 | Crawler::create() |
||
45 | ->setCrawlObserver($observer) |
||
46 | ->setCrawlProfile(new CrawlInternalUrls('https://spatie.be')) |
||
47 | ->startCrawling('https://spatie.be'); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.