Completed
Push — dev ( 7d51be...c4b666 )
by Darko
07:23
created

Popporn   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 304
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 49
eloc 141
dl 0
loc 304
ccs 0
cts 130
cp 0
rs 8.48
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A synopsis() 0 17 5
A covers() 0 19 5
B processSite() 0 49 9
A trailers() 0 21 3
C productInfo() 0 45 14
A genres() 0 11 3
B cast() 0 39 10

How to fix   Complexity   

Complex Class

Complex classes like Popporn often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Popporn, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Blacklight\processing\adult;
4
5
class Popporn extends AdultMovies
6
{
7
    /**
8
     * Define a cookie file location for curl.
9
     *
10
     * @var string string
11
     */
12
    public $cookie = '';
13
14
    /**
15
     * Set this for what you are searching for.
16
     *
17
     * @var string
18
     */
19
    protected $searchTerm = '';
20
21
    /**
22
     * Override if 18 years+ or older
23
     * Define PopPorn url
24
     * Needed Search Queries Constant.
25
     */
26
    private const IF18 = 'https://www.popporn.com/popporn/4';
27
    private const POPURL = 'https://www.popporn.com';
28
    private const TRAILINGSEARCH = '/search&q=';
29
30
    /**
31
     * Sets the directurl for the return results array.
32
     *
33
     * @var string
34
     */
35
    protected $_directUrl = '';
36
37
    /**
38
     * Curl Raw Html.
39
     */
40
    protected $_response;
41
42
    /**
43
     * Results returned from each method.
44
     *
45
     * @var array
46
     */
47
    protected $_res = [];
48
49
    /**
50
     * This is set in the getAll method.
51
     *
52
     * @var string
53
     */
54
    protected $_title = '';
55
56
    /**
57
     * Add this to popurl to get results.
58
     *
59
     * @var string
60
     */
61
    protected $_trailUrl = '';
62
63
    private $_postParams;
64
65
    /**
66
     * Get Box Cover Images.
67
     *
68
     * @return array - boxcover,backcover
69
     */
70
    protected function covers(): array
71
    {
72
        if ($ret = $this->_html->find('div[id=box-art], a[rel=box-art]', 1)) {
73
            $this->_res['boxcover'] = trim($ret->href);
0 ignored issues
show
Bug introduced by
It seems like $ret->href can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
            $this->_res['boxcover'] = trim(/** @scrutinizer ignore-type */ $ret->href);
Loading history...
74
            if (false !== stripos(trim($ret->href), '_aa')) {
75
                $this->_res['backcover'] = str_ireplace('_aa', '_bb', trim($ret->href));
76
            } else {
77
                $this->_res['backcover'] = str_ireplace('.jpg', '_b.jpg', trim($ret->href));
78
            }
79
        } else {
80
            if ($ret = $this->_html->findOne('img.front')) {
81
                $this->_res['boxcover'] = $ret->src;
82
            }
83
            if ($ret = $this->_html->findOne('img.back')) {
84
                $this->_res['backcover'] = $ret->src;
85
            }
86
        }
87
88
        return $this->_res;
89
    }
90
91
    /**
92
     * @return array|mixed
93
     */
94
    protected function synopsis()
95
    {
96
        if ($ret = $this->_html->find('div[id=product-info] ,h3[class=highlight]', 1)) {
97
            if ($ret->next_sibling()->plaintext) {
0 ignored issues
show
Bug introduced by
The method next_sibling() does not exist on voku\helper\SimpleHtmlDomNodeInterface. It seems like you code against a sub-type of voku\helper\SimpleHtmlDomNodeInterface such as voku\helper\SimpleHtmlDomNodeBlank. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

97
            if ($ret->/** @scrutinizer ignore-call */ next_sibling()->plaintext) {
Loading history...
98
                if (stripos(trim($ret->next_sibling()->plaintext), 'POPPORN EXCLUSIVE') === false) {
99
                    $this->_res['synopsis'] = trim($ret->next_sibling()->plaintext);
100
                } else {
101
                    if ($ret->next_sibling()->next_sibling()) {
102
                        $this->_res['synopsis'] = trim($ret->next_sibling()->next_sibling()->next_sibling()->plaintext);
103
                    } else {
104
                        $this->_res['synopsis'] = 'N/A';
105
                    }
106
                }
107
            }
108
        }
109
110
        return $this->_res;
111
    }
112
113
    /**
114
     * @return array|mixed
115
     */
116
    protected function trailers()
117
    {
118
        if ($ret = $this->_html->findOne('input#thickbox-trailer-link')) {
119
            $ret->value = trim($ret->value);
0 ignored issues
show
Bug introduced by
It seems like $ret->value can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

119
            $ret->value = trim(/** @scrutinizer ignore-type */ $ret->value);
Loading history...
120
            $ret->value = str_replace('..', '', $ret->value);
121
            $tmprsp = $this->_response;
122
            $this->_trailUrl = $ret->value;
123
            if (preg_match_all('/productID="\+(?<id>\d+),/', $this->_response, $matches)) {
124
                $productid = $matches['id'][0];
125
                $random = ((float) mt_rand() / (float) mt_getrandmax()) * 5400000000000000;
126
                $this->_trailUrl = '/com/tlavideo/vod/FlvAjaxSupportService.cfc?random='.$random;
127
                $this->_postParams = 'method=pipeStreamLoc&productID='.$productid;
128
                $ret = json_decode(json_decode($this->_response, true), true);
129
                $this->_res['trailers']['baseurl'] = self::POPURL.'/flashmediaserver/trailerPlayer.swf';
130
                $this->_res['trailers']['flashvars'] = 'subscribe=false&image=&file='.self::POPURL.'/'.$ret['LOC'].'&autostart=false';
131
                unset($this->_response);
132
                $this->_response = $tmprsp;
133
            }
134
        }
135
136
        return $this->_res;
137
    }
138
139
    /**
140
     * @param bool $extras
141
     *
142
     * @return array|mixed
143
     */
144
    protected function productInfo($extras = false)
145
    {
146
        $country = false;
147
        if ($ret = $this->_html->findOne('div#lside')) {
148
            foreach ($ret->find('text') as $e) {
149
                $e = trim($e->innertext);
150
                $e = str_replace([', ', '...', '&nbsp;'], '', $e);
151
                if (stripos($e, 'Country:') !== false) {
152
                    $country = true;
153
                }
154
                if ($country === true) {
155
                    if (stripos($e, 'addthis_config') === false) {
156
                        if (! empty($e)) {
157
                            $this->_res['productinfo'][] = $e;
158
                        }
159
                    } else {
160
                        break;
161
                    }
162
                }
163
            }
164
        }
165
166
        $this->_res['productinfo'] = array_chunk($this->_res['productinfo'], 2, false);
167
168
        if ($extras === true) {
169
            $features = false;
170
            if ($this->_html->findOne('ul.stock-information')) {
171
                foreach ($this->_html->find('ul.stock-information') as $ul) {
172
                    foreach ($ul->find('li') as $e) {
173
                        $e = trim($e->plaintext);
174
                        if ($e === 'Features:') {
175
                            $features = true;
176
                            $e = null;
177
                        }
178
                        if ($features === true) {
179
                            if (! empty($e)) {
180
                                $this->_res['extras'][] = $e;
181
                            }
182
                        }
183
                    }
184
                }
185
            }
186
        }
187
188
        return $this->_res;
189
    }
190
191
    /**
192
     * @return array|mixed
193
     */
194
    protected function cast()
195
    {
196
        $cast = false;
197
        $director = false;
198
        $er = [];
199
        if ($ret = $this->_html->findOne('div#lside')) {
200
            foreach ($ret->find('text') as $e) {
201
                $e = trim($e->innertext);
202
                $e = str_replace([',', '&nbsp;'], '', $e);
203
                if (stripos($e, 'Cast') !== false) {
204
                    $cast = true;
205
                }
206
                $e = str_replace('Cast:', '', $e);
207
                if ($cast === true) {
208
                    if (stripos($e, 'Director:') !== false) {
209
                        $director = true;
210
                        $e = null;
211
                    }
212
213
                    if ($director === true) {
214
                        if (! empty($e)) {
215
                            $this->_res['director'] = $e;
216
                            $director = false;
217
                            $e = null;
218
                        }
219
                    }
220
                    if (stripos($e, 'Country:') === false) {
221
                        if (! empty($e)) {
222
                            $er[] = $e;
223
                        }
224
                    } else {
225
                        break;
226
                    }
227
                }
228
            }
229
        }
230
        $this->_res['cast'] = $er;
231
232
        return $this->_res;
233
    }
234
235
    /**
236
     * Gets categories.
237
     *
238
     * @return array
239
     */
240
    protected function genres()
241
    {
242
        $genres = [];
243
        if ($ret = $this->_html->find('div[id=thekeywords], p[class=keywords]', 1)) {
244
            foreach ($ret->find('a') as $e) {
245
                $genres[] = trim($e->plaintext);
246
            }
247
        }
248
        $this->_res['genres'] = $genres;
249
250
        return $this->_res;
251
    }
252
253
    /**
254
     * Searches for match against searchterm.
255
     *
256
     * @param string $movie
257
     *
258
     * @return bool , true if search >= 90%
259
     */
260
    public function processSite($movie): bool
261
    {
262
        if (! empty($movie)) {
263
            $this->_trailUrl = self::TRAILINGSEARCH.$movie;
264
            $this->_response = getRawHtml(self::POPURL.$this->_trailUrl, $this->cookie);
265
            if ($this->_response !== false) {
266
                if ($ret = $this->_html->loadHtml($this->_response)->find('div.product-info, div.title', 1)) {
267
                    $this->_title = trim($ret->plaintext);
268
                    $title = str_replace('XXX', '', $ret->plaintext);
269
                    $title = trim(preg_replace('/\(.*?\)|[._-]/i', ' ', $title));
270
                    similar_text(strtolower($movie), strtolower($title), $p);
271
                    if ($p >= 90) {
272
                        if ($ret = $ret->findOne('a')) {
0 ignored issues
show
Bug introduced by
The method findOne() does not exist on voku\helper\SimpleHtmlDomNodeInterface. Did you maybe mean find()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

272
                        if ($ret = $ret->/** @scrutinizer ignore-call */ findOne('a')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
273
                            $this->_trailUrl = trim($ret->href);
0 ignored issues
show
Bug introduced by
It seems like $ret->href can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

273
                            $this->_trailUrl = trim(/** @scrutinizer ignore-type */ $ret->href);
Loading history...
274
                            unset($this->_response);
275
                            $this->_response = getRawHtml(self::POPURL.$this->_trailUrl, $this->cookie);
276
                            if ($this->_response !== false) {
277
                                $this->_html->loadHtml($this->_response);
278
                                if ($ret = $this->_html->findOne('#link-to-this')) {
279
                                    $this->_directUrl = trim($ret->href);
280
                                    unset($this->_response);
281
                                    $this->_response = getRawHtml($this->_directUrl, $this->cookie);
282
                                    $this->_html->loadHtml($this->_response);
0 ignored issues
show
Bug introduced by
It seems like $this->_response can also be of type false; however, parameter $html of voku\helper\HtmlDomParser::loadHtml() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

282
                                    $this->_html->loadHtml(/** @scrutinizer ignore-type */ $this->_response);
Loading history...
283
284
                                    return true;
285
                                }
286
287
                                return false;
288
                            }
289
                        }
290
291
                        return true;
292
                    }
293
                }
294
            } else {
295
                $this->_response = getRawHtml(self::IF18, $this->cookie);
296
                if ($this->_response !== false) {
297
                    $this->_html->loadHtml($this->_response);
298
299
                    return true;
300
                }
301
302
                return false;
303
            }
304
305
            return false;
306
        }
307
308
        return false;
309
    }
310
}
311