Completed
Push — master ( ebed0b...7356ba )
by Jeremy
04:47
created

SoundServices::getAllSounds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Models\Sound;
6
7
class SoundServices
8
{
9
    /**
10
     * Get the Sounds from Database.
11
     *
12
     * @param int $id Sound Id
13
     *
14
     * @return Collection The Sound
0 ignored issues
show
Bug introduced by
The type App\Services\Collection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
     */
16
    public static function getSound($id)
17
    {
18
        if (!$id) {
19
            return abort(404);
0 ignored issues
show
Bug Best Practice introduced by
The expression return abort(404) returns the type void which is incompatible with the documented return type App\Services\Collection.
Loading history...
Bug introduced by
Are you sure the usage of abort(404) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
20
        }
21
22
        return Sound::findOrFail($id);
23
    }
24
25
    public static function getAllSounds()
26
    {
27
        return Sound::all();
28
    }
29
30
    /**
31
     * Gets the sorted sounds.
32
     *
33
     * @return collection The sorted sounds.
0 ignored issues
show
Bug introduced by
The type App\Services\collection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
     */
35
    public static function getSortedSounds()
36
    {
37
        return Sound::sortedSounds()->get();
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Sound::sortedSounds()->get() returns the type Illuminate\Database\Eloquent\Collection which is incompatible with the documented return type App\Services\collection.
Loading history...
38
    }
39
40
    /**
41
     * Gets the enabled and sorted sounds.
42
     *
43
     * @return collection The enabled sorted sounds.
44
     */
45
    public static function getEnabledSortedSounds()
46
    {
47
        return Sound::enabledSounds()->sortedSounds()->get();
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Sound:...->sortedSounds()->get() returns the type Illuminate\Database\Eloquent\Collection which is incompatible with the documented return type App\Services\collection.
Loading history...
48
    }
49
50
    /**
51
     * Gets the blank sound.
52
     *
53
     * @return Empty Sound Collection.
0 ignored issues
show
Bug introduced by
The type App\Services\Empty was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
     */
55
    public static function getBlankSound()
56
    {
57
        return new Sound;
0 ignored issues
show
Bug Best Practice introduced by
The expression return new App\Models\Sound() returns the type App\Models\Sound which is incompatible with the documented return type App\Services\Empty.
Loading history...
58
    }
59
60
    /**
61
     * Update a sound
62
     *
63
     * @param collection $sound     The sound
64
     * @param array $soundData      The sound data
65
     *
66
     * @return Collection Sound
67
     */
68
    public static function updateSound(Sound $sound, $soundData)
69
    {
70
        $sound->fill($soundData);
71
        $sound->save();
72
73
        return $sound;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $sound returns the type App\Models\Sound which is incompatible with the documented return type App\Services\Collection.
Loading history...
74
    }
75
76
    /**
77
     * Update a sound enabled/disabled
78
     *
79
     * @param int $soundId      The sound identifier
80
     * @param boolean $status   The status
81
     *
82
     * @return collection \App\Models\Sound\Sound $sound
83
     */
84
    public static function updateSoundStatus($soundId, $status)
85
    {
86
        $sound = self::getSound($soundId);
87
        $sound->enabled = $status;
88
        $sound->save();
89
90
        return $sound;
91
    }
92
93
    /**
94
     * Stores a new sound.
95
     *
96
     * @param array $soundData  The sound data
97
     *
98
     * @return collection $newSound The newly stored sound
99
     */
100
    public static function storeNewSound($soundData)
101
    {
102
        $lastSound = collect(Sound::sortedSounds()->get())->last();
103
        $sort_order = ['sort_order' => $lastSound->sort_order + 1];
104
        $newSound = Sound::create(array_merge($soundData, $sort_order));
105
106
        return $newSound;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $newSound returns the type App\Models\Sound which is incompatible with the documented return type App\Services\collection.
Loading history...
107
    }
108
109
    /**
110
     * Delete a sound
111
     *
112
     * @param collection $sound  The sound
113
     *
114
     * @return Collection of deleted Sound
115
     */
116
    public static function deleteSound(Sound $sound)
117
    {
118
        $sound->delete();
119
120
        return $sound;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $sound returns the type App\Models\Sound which is incompatible with the documented return type App\Services\Collection.
Loading history...
121
    }
122
}
123