Completed
Pull Request — master (#30)
by vincent
03:53
created

Favorite   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 61
loc 61
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getMovies() 4 4 1
A getTVShows() 4 4 1
A markMovieAsFavorite() 4 4 1
A unmarkMovieAsFavorite() 4 4 1
A markTVShowAsFavorite() 4 4 1
A unmarkTVShowAsFavorite() 4 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
 * This file is part of the Tmdb package.
4
 *
5
 * (c) Vincent Faliès <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Vincent Faliès <[email protected]>
11
 * @copyright Copyright (c) 2017
12
 */
13
14
15
namespace VfacTmdb\Account;
16
17
use VfacTmdb\Results;
18
use VfacTmdb\Abstracts\Account;
19
20
/**
21
 * Class to manipulate account favorite
22
 * @package Tmdb
23
 * @author Vincent Faliès <[email protected]>
24
 * @copyright Copyright (c) 2017
25
 */
26 View Code Duplication
class Favorite extends Account
0 ignored issues
show
Duplication introduced by
This class 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...
27
{
28
29
    /**
30
     * Get account favorite movies
31
     * @return \Generator|Results\Movie
32
     */
33 1
    public function getMovies() : \Generator
34
    {
35 1
        return $this->getAccountListItems('favorite', 'movies', Results\Movie::class);
36
    }
37
38
    /**
39
     * Get account favorite tvshows
40
     * @return \Generator|Results\TVShow
41
     */
42 1
    public function getTVShows() : \Generator
43
    {
44 1
        return $this->getAccountListItems('favorite', 'tv', Results\TVShow::class);
45
    }
46
47
    /**
48
     * Marl a movie as favorite
49
     * @param  int    $movie_id Movie id
50
     * @return Favorite
51
     */
52 2
    public function markMovieAsFavorite(int $movie_id) : Favorite
53
    {
54 2
        return $this->setListItem('favorite', 'movie', $movie_id, true);
55
    }
56
    /**
57
58
     * Unmark a movie as favorite
59
     * @param int $movie_id Movie id
60
     * @return Favorite
61
     */
62 1
    public function unmarkMovieAsFavorite(int $movie_id) : Favorite
63
    {
64 1
        return $this->setListItem('favorite', 'movie', $movie_id, false);
65
    }
66
67
    /**
68
     * Mark a TV show as favorkite
69
     * @param  int $tvshow_id TV show id
70
     * @return Favorite
71
     */
72 1
    public function markTVShowAsFavorite(int $tvshow_id) : Favorite
73
    {
74 1
        return $this->setListItem('favorite', 'tv', $tvshow_id, true);
75
    }
76
77
    /**
78
     * Unmark a TV show as favorite
79
     * @param  int $tvshow_id TV Show id
80
     * @return Favorite
81
     */
82 1
    public function unmarkTVShowAsFavorite(int $tvshow_id) : Favorite
83
    {
84 1
        return $this->setListItem('favorite', 'tv', $tvshow_id, false);
85
    }
86
}
87