GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#31)
by Jérôme
10:19 queued 07:48
created

Sketchfab   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 5
Metric Value
wmc 9
c 6
b 1
f 5
lcom 1
cbo 2
dl 0
loc 57
ccs 29
cts 29
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateUrl() 0 9 2
A normalizeUrl() 0 12 3
A modifyResponse() 0 8 2
A fakeResponse() 0 15 2
1
<?php
2
/**
3
 * Sketchfab.php
4
 *
5
 * @package Providers
6
 * @author Michael Pratt <[email protected]>
7
 * @link   http://www.michael-pratt.com/
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 Embera\Providers;
14
15
/**
16
 * The sketchfab.com Provider
17
 * @link http://sketchfab.com
18
 */
19
class Sketchfab extends \Embera\Adapters\Service
20
{
21
    /** inline {@inheritdoc} */
22
    protected $apiUrl = 'https://sketchfab.com/oembed';
23
24
    /** inline {@inheritdoc} */
25 2
    protected function validateUrl()
26
    {
27 2
        $this->url->stripLastSlash();
28
29
        return (
30 2
            preg_match('~sketchfab\.com/models/(?:[^/]+)$~i', $this->url) ||
31 2
            preg_match('~sketchfab\.com/(?:[^/]+)/folders/(?:[^/]+)$~i', $this->url)
32 2
        );
33
    }
34
35
    /** inline {@inheritdoc} */
36 2
    protected function normalizeUrl()
37
    {
38 2
        $this->url->stripWWW();
39 2
        $this->url->convertToHttps();
40
41
        // old urls
42 2
        if (preg_match('~sketchfab\.com/show/([^/]+)/?$~i', $this->url, $matches)) {
43 2
            $this->url = new \Embera\Url('https://sketchfab.com/models/' . $matches[1]);
44 2
        } else if (preg_match('~(/embed/?)$~', $this->url)) {
45 2
            $this->url = new \Embera\Url(preg_replace('~(/embed/?)$~', '', $this->url));
0 ignored issues
show
Bug introduced by
It seems like preg_replace('~(/embed/?)$~', '', $this->url) targeting preg_replace() can also be of type array<integer,string>; however, Embera\Url::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
46 2
        }
47 2
    }
48
49
    /** inline {@inheritdoc} */
50 2
    protected function modifyResponse(array $response = array())
51
    {
52 2
        if (!empty($response['html'])) {
53 2
            $response['html'] = preg_replace('~<p(.*)>(.*)</p>~is', '', $response['html']);
54 2
        }
55
56 2
        return $response;
57
    }
58
59
    /** inline {@inheritdoc} */
60 2
    public function fakeResponse()
61
    {
62 2
        if (preg_match('~sketchfab\.com/(?:[^/]+)/folders/([^/]+)$~i', $this->url, $m)) {
63 1
            $url = 'https://sketchfab.com/playlists/embed?folder=' . $m['1'];
64 1
        } else {
65 1
            $url = str_replace('/show/', '/embed/', $this->url) . '/embed';
66
        }
67
68
        return array(
69 2
            'type' => 'rich',
70 2
            'provider_name' => 'Sketchfab',
71 2
            'provider_url' => 'http://sketchfab.com',
72 2
            'html' => '<iframe width="{width}" height="{height}" src="' . $url . '" frameborder="0" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>'
73 2
        );
74
    }
75
}
76
77
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
78