Completed
Push — master ( 5eb3ff...ebed0b )
by Jeremy
12:36
created

SoundServices::updateSound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
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
    /**
26
     * Gets the sorted sounds.
27
     *
28
     * @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...
29
     */
30
    public static function getSortedSounds()
31
    {
32
        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...
33
    }
34
35
    /**
36
     * Gets the enabled and sorted sounds.
37
     *
38
     * @return collection The enabled sorted sounds.
39
     */
40
    public static function getEnabledSortedSounds()
41
    {
42
        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...
43
    }
44
45
    /**
46
     * Gets the blank sound.
47
     *
48
     * @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...
49
     */
50
    public static function getBlankSound()
51
    {
52
        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...
53
    }
54
55
    /**
56
     * Update a sound
57
     *
58
     * @param collection $sound     The sound
59
     * @param array $soundData      The sound data
60
     *
61
     * @return Collection Sound
62
     */
63
    public static function updateSound($sound, $soundData)
64
    {
65
        $sound->fill($soundData);
66
        $sound->save();
67
68
        return $sound;
69
    }
70
71
    /**
72
     * Stores a new sound.
73
     *
74
     * @param array $soundData  The sound data
75
     *
76
     * @return collection $newSound The newly stored sound
77
     */
78
    public static function storeNewSound($soundData)
79
    {
80
        $lastSound = collect(Sound::sortedSounds()->get())->last();
81
        $sort_order = ['sort_order' => $lastSound->sort_order + 1];
82
        $newSound = Sound::create(array_merge($soundData, $sort_order));
83
84
        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...
85
    }
86
87
    /**
88
     * Delete a sound
89
     *
90
     * @param collection $sound  The sound
91
     *
92
     * @return Collection of deleted Sound
93
     */
94
    public static function deleteSound($sound)
95
    {
96
        $sound->delete();
97
98
        return $sound;
99
    }
100
}
101