ApiTransformer   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 28
eloc 63
c 4
b 2
f 0
dl 0
loc 80
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
F transform() 0 68 27
A __construct() 0 3 1
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 ApiTransformer 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
    public function transform(Release $releases): array
23
    {
24
        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...
25
            return [
26
                '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...
27
                '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...
28
                'url' => url('/').'/getnzb?id='.$releases->guid.'.nzb'.'&r='.$this->user->api_token,
29
                'category' => $releases->categories_id,
30
                'category_name' => $releases->category_name,
31
                '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...
32
                '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...
33
                '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...
34
                'poster' => $releases->fromname,
0 ignored issues
show
Bug introduced by
The property fromname 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
                'imdbid' => $releases->imdbid !== null && $releases->imdbid !== 0 ? $releases->imdbid : $this->null(),
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...
36
                'tmdbid' => $releases->tmdbid !== null && $releases->tmdbid !== 0 ? $releases->tmdbid : $this->null(),
0 ignored issues
show
Bug introduced by
The property tmdbid 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
                'traktid' => $releases->traktid !== null && $releases->traktid !== 0 ? $releases->traktid : $this->null(),
0 ignored issues
show
Bug introduced by
The property traktid does not exist on App\Models\Release. Did you mean trakt?
Loading history...
38
                'grabs' => $releases->grabs !== 0 ? $releases->grabs : $this->null(),
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 ? $releases->comments : $this->null(),
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
                'group' => $releases->group_name,
43
            ];
44
        }
45
46
        if (\in_array($releases->categories_id, Category::TV_GROUP, false)) {
47
            return [
48
                'title' => $releases->searchname,
49
                'details' => url('/').'/details/'.$releases->guid,
50
                'url' => url('/').'/getnzb?id='.$releases->guid.'.nzb'.'&r='.$this->user->api_token,
51
                'category' => $releases->categories_id,
52
                'category_name' => $releases->category_name,
53
                'added' => Carbon::parse($releases->adddate)->toRssString(),
54
                'size' => $releases->size,
55
                'files' => $releases->totalpart,
56
                'poster' => $releases->fromname,
57
                'episode_title' => $releases->title ?? $this->null(),
58
                'season' => $releases->series ?? $this->null(),
0 ignored issues
show
Bug introduced by
The property series 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...
59
                'episode' => $releases->episode ?? $this->null(),
60
                'tvairdate' => $releases->firstaired ?? $this->null(),
61
                'tvdbid' => $releases->tvdb !== null && $releases->tvdb !== 0 ? $releases->tvdb : $this->null(),
62
                'traktid' => $releases->trakt !== null && $releases->trakt !== 0 ? $releases->trakt : $this->null(),
63
                'tvrageid' => $releases->tvrage !== null && $releases->tvrage !== 0 ? $releases->tvrage : $this->null(),
64
                'tvmazeid' => $releases->tvmaze !== null && $releases->tvmaze !== 0 ? $releases->tvmaze : $this->null(),
65
                'imdbid' => $releases->imdb !== null && $releases->imdb !== 0 ? $releases->imdb : $this->null(),
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...
66
                'tmdbid' => $releases->tmdb !== null && $releases->tmdb !== 0 ? $releases->tmdb : $this->null(),
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...
67
                'grabs' => $releases->grabs !== 0 ? $releases->grabs : $this->null(),
68
                'comments' => $releases->comments !== 0 ? $releases->comments : $this->null(),
69
                'password' => $releases->passwordstatus,
70
                'usenetdate' => Carbon::parse($releases->postdate)->toRssString(),
71
                'group' => $releases->group_name,
72
            ];
73
        }
74
75
        return [
76
            'title' => $releases->searchname,
77
            'details' => url('/').'/details/'.$releases->guid,
78
            'url' => url('/').'/getnzb?id='.$releases->guid.'.nzb'.'&r='.$this->user->api_token,
79
            'category' => $releases->categories_id,
80
            'category_name' => $releases->category_name,
81
            'added' => Carbon::parse($releases->adddate)->toRssString(),
82
            'size' => $releases->size,
83
            'files' => $releases->totalpart,
84
            'poster' => $releases->fromname,
85
            'grabs' => $releases->grabs !== 0 ? $releases->grabs : $this->null(),
86
            'comments' => $releases->comments !== 0 ? $releases->comments : $this->null(),
87
            'password' => $releases->passwordstatus,
88
            'usenetdate' => Carbon::parse($releases->postdate)->toRssString(),
89
            'group' => $releases->group_name,
90
        ];
91
    }
92
}
93