Completed
Pull Request — master (#8)
by Ricardo
01:45
created

FacebookServiceAdapter   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 79
Duplicated Lines 10.13 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 8
loc 79
ccs 0
cts 50
cp 0
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getServiceName() 0 4 1
A hasThumbnail() 0 4 1
A getThumbNailSizes() 0 4 1
A getThumbnail() 8 8 2
A getSmallThumbnail() 0 4 1
A getMediumThumbnail() 0 4 1
A getLargeThumbnail() 0 4 1
A getLargestThumbnail() 0 4 1
A getEmbedUrl() 0 4 1
A isEmbeddable() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
3
namespace RicardoFiorani\Adapter\Facebook;
4
5
use RicardoFiorani\Adapter\AbstractServiceAdapter;
6
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
7
use RicardoFiorani\Exception\ThumbnailSizeNotAvailable;
8
use RicardoFiorani\Renderer\EmbedRendererInterface;
9
10
class FacebookServiceAdapter extends AbstractServiceAdapter
11
{
12
    const THUMBNAIL_SIZE_DEFAULT = 'default';
13
14
    public function __construct(string $url, string $pattern, EmbedRendererInterface $renderer)
15
    {
16
        $match = array();
17
        preg_match($pattern, $url, $match);
18
        $this->setVideoId($match[1]);
19
20
        return parent::__construct($url, $pattern, $renderer);
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
21
    }
22
23
    public function getServiceName(): string
24
    {
25
        return 'Facebook';
26
    }
27
28
    public function hasThumbnail(): bool
29
    {
30
        return true;
31
    }
32
33
    public function getThumbNailSizes(): array
34
    {
35
        return array(self::THUMBNAIL_SIZE_DEFAULT);
36
    }
37
38 View Code Duplication
    public function getThumbnail(string $size, bool $forceSecure = false): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
39
    {
40
        if (false == in_array($size, $this->getThumbNailSizes())) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
41
            throw new InvalidThumbnailSizeException();
42
        }
43
44
        return $this->getScheme($forceSecure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture';
45
    }
46
47
    /**
48
     * @throws ThumbnailSizeNotAvailable
49
     */
50
    public function getSmallThumbnail(bool $forceSecure = false): string
51
    {
52
        throw new ThumbnailSizeNotAvailable();
53
    }
54
55
    /**
56
     * @throws InvalidThumbnailSizeException
57
     */
58
    public function getMediumThumbnail(bool $forceSecure = false): string
59
    {
60
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure);
61
    }
62
63
    /**
64
     * @throws ThumbnailSizeNotAvailable
65
     */
66
    public function getLargeThumbnail(bool $forceSecure = false): string
67
    {
68
        throw new ThumbnailSizeNotAvailable();
69
    }
70
71
    /**
72
     * @throws InvalidThumbnailSizeException
73
     */
74
    public function getLargestThumbnail(bool $forceSecure = false): string
75
    {
76
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure);
77
    }
78
79
    public function getEmbedUrl(bool $forceAutoplay = false, bool $forceSecure = false): string
80
    {
81
        return $this->getScheme($forceSecure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId();
82
    }
83
84
    public function isEmbeddable(): bool
85
    {
86
        return true;
87
    }
88
}
89