Passed
Push — master ( 4f5b3b...1c5d75 )
by Darko
09:48
created

DetailsTransformer::transform()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 57
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 49
c 0
b 0
f 0
dl 0
loc 57
rs 9.1127
cc 3
nc 3
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Transformers;
4
5
use App\Models\Category;
6
use App\Models\Release;
7
use Illuminate\Support\Carbon;
8
use League\Fractal\TransformerAbstract;
9
10
class DetailsTransformer extends TransformerAbstract
11
{
12
    protected $user;
13
14
    /**
15
     * ApiTransformer constructor.
16
     */
17
    public function __construct($user)
18
    {
19
        $this->user = $user;
20
    }
21
22
    /**
23
     * A Fractal transformer.
24
     */
25
    public function transform(Release $releases): array
26
    {
27
        if (\in_array($releases->categories_id, Category::MOVIES_GROUP, false)) {
0 ignored issues
show
Bug introduced by
The property categories_id does not exist on App\Models\Release. Did you mean category_ids?
Loading history...
28
            return [
29
                'title' => $releases->searchname,
0 ignored issues
show
Bug introduced by
The property searchname does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
30
                'details' => url('/').'/details/'.$releases->guid,
0 ignored issues
show
Bug introduced by
The property guid does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
31
                'url' => url('/').'/getnzb?id='.$releases->guid.'.nzb'.'&r='.$this->user->api_token,
32
                'category' => $releases->categories_id,
33
                'category_name' => $releases->category_name,
34
                'added' => Carbon::parse($releases->adddate)->toRssString(),
0 ignored issues
show
Bug introduced by
The property adddate does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
35
                'size' => $releases->size,
0 ignored issues
show
Bug introduced by
The property size does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
36
                'files' => $releases->totalpart,
0 ignored issues
show
Bug introduced by
The property totalpart does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
37
                'imdbid' => $releases->imdbid,
0 ignored issues
show
Bug introduced by
The property imdbid does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
38
                'grabs' => $releases->grabs,
0 ignored issues
show
Bug introduced by
The property grabs does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
39
                'comments' => $releases->comments,
0 ignored issues
show
Bug introduced by
The property comments does not exist on App\Models\Release. Did you mean comment?
Loading history...
40
                'password' => $releases->passwordstatus,
0 ignored issues
show
Bug introduced by
The property passwordstatus does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
41
                'usenetdate' => Carbon::parse($releases->postdate)->toRssString(),
0 ignored issues
show
Bug introduced by
The property postdate does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
42
            ];
43
        }
44
45
        if (\in_array($releases->categories_id, Category::TV_GROUP, false)) {
46
            return [
47
                'title' => $releases->searchname,
48
                'details' => url('/').'/details/'.$releases->guid,
49
                'link' => url('/').'/getnzb?id='.$releases->guid.'.nzb'.'&i='.'&r='.$this->user->api_token,
50
                'category' => $releases->categories_id,
51
                'category_name' => $releases->category_name,
52
                'added' => Carbon::parse($releases->adddate)->toRssString(),
53
                'size' => $releases->size,
54
                'files' => $releases->totalpart,
55
                'tvairdate' => $releases->firstaired,
56
                'tvdbid' => $releases->tvdb,
57
                'traktid' => $releases->trakt,
58
                'tvrageid' => $releases->tvrage,
59
                'tvmazeid' => $releases->tvmaze,
60
                'imdbid' => $releases->imdb,
0 ignored issues
show
Bug introduced by
The property imdb does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
61
                'tmdbid' => $releases->tmdb,
0 ignored issues
show
Bug introduced by
The property tmdb does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
62
                'grabs' => $releases->grabs,
63
                'comments' => $releases->comments,
64
                'password' => $releases->passwordstatus,
65
                'usenetdate' => Carbon::parse($releases->postdate)->toRssString(),
66
            ];
67
        }
68
69
        return [
70
            'title' => $releases->searchname,
71
            'details' => url('/').'/details/'.$releases->guid,
72
            'link' => url('/').'/getnzb?id='.$releases->guid.'.nzb'.'&i='.'&r='.$this->user->api_token,
73
            'category' => $releases->categories_id,
74
            'category_name' => $releases->category_name,
75
            'added' => Carbon::parse($releases->adddate)->toRssString(),
76
            'size' => $releases->size,
77
            'files' => $releases->totalpart,
78
            'grabs' => $releases->grabs,
79
            'comments' => $releases->comments,
80
            'password' => $releases->passwordstatus,
81
            'usenetdate' => Carbon::parse($releases->postdate)->toRssString(),
82
        ];
83
    }
84
}
85