ScrapePodcast   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 107
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A itunes() 0 6 1
A digitalPodcast() 0 6 1
A limit() 0 6 1
A search() 0 4 1
A find() 0 4 1
A feed() 0 4 1
A original() 0 6 1
A engine() 0 6 2
1
<?php
2
namespace Tzsk\ScrapePod;
3
4
use Tzsk\ScrapePod\Contracts\VendorInterface;
5
use Tzsk\ScrapePod\Vendors\DigitalPodcast;
6
use Tzsk\ScrapePod\Vendors\Itunes;
7
8
class ScrapePodcast
9
{
10
    /**
11
     * @var VendorInterface
12
     */
13
    protected $vendor;
14
15
    /**
16
     * @var int
17
     */
18
    protected $count = 15;
19
20
    /**
21
    * @var bool
22
    */
23
    protected $isOrginal = false;
24
25
    /**
26
     * ScrapePodcast constructor.
27
     */
28
    public function __construct()
29
    {
30
        $this->vendor = new Itunes();
31
    }
32
33
    /**
34
     * @return ScrapePodcast
35
     */
36
    public function itunes()
37
    {
38
        $this->vendor = new Itunes();
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return ScrapePodcast
45
     */
46
    public function digitalPodcast()
47
    {
48
        $this->vendor = new DigitalPodcast();
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param int $count
55
     *
56
     * @return ScrapePodcast
57
     */
58
    public function limit($count)
59
    {
60
        $this->count = $count;
61
62
        return $this;
63
    }
64
65
    /**
66
     * @param string $term
67
     *
68
     * @return array
69
     */
70
    public function search($term)
71
    {
72
        return $this->engine()->get($term);
73
    }
74
75
    /**
76
     * @param $id
77
     *
78
     * @return array
79
     */
80
    public function find($id)
81
    {
82
        return $this->engine()->get((int) $id);
83
    }
84
85
    /**
86
     * @param string $feed
87
     *
88
     * @return array
89
     */
90
    public function feed($feed)
91
    {
92
        return $this->engine()->find($feed);
93
    }
94
95
    /**
96
     * @return ScrapePodcast
97
     */
98
    public function original()
99
    {
100
        $this->isOrginal = true;
101
102
        return $this;
103
    }
104
105
    /**
106
     * @return PodcastScraper
107
     */
108
    protected function engine()
109
    {
110
        $engine = (new PodcastScraper($this->vendor))->limit($this->count);
111
112
        return $this->isOrginal ? $engine->original() : $engine;
113
    }
114
}
115