1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This is part of the webuni/srazy-api-client. |
5
|
|
|
* |
6
|
|
|
* (c) Martin Hasoň <[email protected]> |
7
|
|
|
* (c) Webuni s.r.o. <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Webuni\Srazy\Api; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
16
|
|
|
use Webuni\Srazy\Model\Series; |
17
|
|
|
use Webuni\Srazy\Page\CommunityPage; |
18
|
|
|
use Webuni\Srazy\Page\SearchPage; |
19
|
|
|
use Webuni\Srazy\Page\SeriesPage; |
20
|
|
|
|
21
|
|
|
class SeriesApi extends AbstractApi |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @return Series[]|ArrayCollection |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
public function find($series) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$crawler = $this->client->get(sprintf('/hledat/?s=%s', urlencode($series))); |
29
|
|
|
$page = new SearchPage($crawler, $this->client); |
30
|
|
|
|
31
|
|
|
return $page->getSeries(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function get($series) |
35
|
|
|
{ |
36
|
|
|
$url = $series; |
37
|
|
|
if ($series instanceof Series) { |
38
|
|
|
$url = $series->getUri(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$crawler = $this->client->get($url.'/terminy'); |
42
|
|
|
$page = new SeriesPage($crawler, $this->client); |
43
|
|
|
|
44
|
|
|
return $page->getSeries(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getFollowers(Series $series) |
48
|
|
|
{ |
49
|
|
|
$crawler = $this->client->get($series->getUri().'/komunita'); |
50
|
|
|
$page = new CommunityPage($crawler, $this->client); |
51
|
|
|
|
52
|
|
|
$followers = $page->getUsers(); |
53
|
|
|
$series->setFollowers($followers); |
54
|
|
|
|
55
|
|
|
return $followers; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/*public function getEvents(Series $series) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$crawler = $this->client->get($series->getUri().'/terminy'); |
61
|
|
|
$page = new SeriesPage($crawler, $this->client); |
62
|
|
|
|
63
|
|
|
return $page->getEvents($series); |
64
|
|
|
}*/ |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.