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

DetailsTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 52
c 0
b 0
f 0
dl 0
loc 72
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A transform() 0 57 3
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