jeremykenedy /
laravel-soundboard
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Services; |
||||
| 4 | |||||
| 5 | use App\Models\Sound; |
||||
| 6 | use Illuminate\Support\Facades\File; |
||||
| 7 | |||||
| 8 | class SoundServices |
||||
| 9 | { |
||||
| 10 | /** |
||||
| 11 | * Get the Sounds from Database. |
||||
| 12 | * |
||||
| 13 | * @param int $id Sound Id |
||||
| 14 | * |
||||
| 15 | * @return Collection The Sound |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | */ |
||||
| 17 | public static function getSound($id) |
||||
| 18 | { |
||||
| 19 | if (!$id) { |
||||
| 20 | return abort(404); |
||||
|
0 ignored issues
–
show
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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 21 | } |
||||
| 22 | |||||
| 23 | return Sound::findOrFail($id); |
||||
| 24 | } |
||||
| 25 | |||||
| 26 | public static function getAllSounds() |
||||
| 27 | { |
||||
| 28 | return Sound::all(); |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Gets the sorted sounds. |
||||
| 33 | * |
||||
| 34 | * @return collection The sorted sounds. |
||||
|
0 ignored issues
–
show
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 35 | */ |
||||
| 36 | public static function getSortedSounds() |
||||
| 37 | { |
||||
| 38 | return Sound::sortedSounds()->get(); |
||||
|
0 ignored issues
–
show
|
|||||
| 39 | } |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * Gets the enabled and sorted sounds. |
||||
| 43 | * |
||||
| 44 | * @return collection The enabled sorted sounds. |
||||
| 45 | */ |
||||
| 46 | public static function getEnabledSortedSounds() |
||||
| 47 | { |
||||
| 48 | return Sound::enabledSounds()->sortedSounds()->get(); |
||||
|
0 ignored issues
–
show
|
|||||
| 49 | } |
||||
| 50 | |||||
| 51 | /** |
||||
| 52 | * Gets the blank sound. |
||||
| 53 | * |
||||
| 54 | * @return Empty Sound Collection. |
||||
|
0 ignored issues
–
show
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 55 | */ |
||||
| 56 | public static function getBlankSound() |
||||
| 57 | { |
||||
| 58 | return new Sound(); |
||||
|
0 ignored issues
–
show
|
|||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * Update a sound. |
||||
| 63 | * |
||||
| 64 | * @param collection $sound The sound |
||||
| 65 | * @param array $soundData The sound data |
||||
| 66 | * |
||||
| 67 | * @return Collection Sound |
||||
| 68 | */ |
||||
| 69 | public static function updateSound(Sound $sound, $soundData) |
||||
| 70 | { |
||||
| 71 | $sound->fill($soundData); |
||||
| 72 | $sound->save(); |
||||
| 73 | |||||
| 74 | return $sound; |
||||
|
0 ignored issues
–
show
|
|||||
| 75 | } |
||||
| 76 | |||||
| 77 | /** |
||||
| 78 | * Update a sound enabled/disabled. |
||||
| 79 | * |
||||
| 80 | * @param int $soundId The sound identifier |
||||
| 81 | * @param bool $status The status |
||||
| 82 | * |
||||
| 83 | * @return collection \App\Models\Sound\Sound $sound |
||||
| 84 | */ |
||||
| 85 | public static function updateSoundStatus($soundId, $status) |
||||
| 86 | { |
||||
| 87 | $sound = self::getSound($soundId); |
||||
| 88 | $sound->enabled = $status; |
||||
| 89 | $sound->save(); |
||||
| 90 | |||||
| 91 | return $sound; |
||||
| 92 | } |
||||
| 93 | |||||
| 94 | /** |
||||
| 95 | * Stores a new sound. |
||||
| 96 | * |
||||
| 97 | * @param array $soundData The sound data |
||||
| 98 | * |
||||
| 99 | * @return collection $newSound The newly stored sound |
||||
| 100 | */ |
||||
| 101 | public static function storeNewSound($soundData) |
||||
| 102 | { |
||||
| 103 | $lastSound = collect(Sound::sortedSounds()->get())->last(); |
||||
| 104 | $sort_order = ['sort_order' => $lastSound->sort_order + 1]; |
||||
| 105 | $newSound = Sound::create(array_merge($soundData, $sort_order)); |
||||
| 106 | |||||
| 107 | return $newSound; |
||||
|
0 ignored issues
–
show
|
|||||
| 108 | } |
||||
| 109 | |||||
| 110 | /** |
||||
| 111 | * Delete a sound. |
||||
| 112 | * |
||||
| 113 | * @param collection $sound The sound |
||||
| 114 | * |
||||
| 115 | * @return Collection of deleted Sound |
||||
| 116 | */ |
||||
| 117 | public static function deleteSound(Sound $sound) |
||||
| 118 | { |
||||
| 119 | $sound->delete(); |
||||
| 120 | |||||
| 121 | return $sound; |
||||
|
0 ignored issues
–
show
|
|||||
| 122 | } |
||||
| 123 | |||||
| 124 | /** |
||||
| 125 | * Check for sounds and recording file directory existance and get any files contained within. |
||||
| 126 | * |
||||
| 127 | * @return array of collections |
||||
| 128 | */ |
||||
| 129 | public static function checkAndPullSoundsAndRecordings() |
||||
| 130 | { |
||||
| 131 | $uploadedFilePath = config('soundboard.folders.uploads').'/'; |
||||
| 132 | $recordedFilePath = $uploadedFilePath.config('soundboard.folders.recordings').'/'; |
||||
| 133 | $fileTypes = 'wav'; |
||||
| 134 | |||||
| 135 | if (!File::exists($uploadedFilePath)) { |
||||
| 136 | File::makeDirectory($uploadedFilePath); |
||||
| 137 | } |
||||
| 138 | |||||
| 139 | if (!File::exists($recordedFilePath)) { |
||||
| 140 | File::makeDirectory($recordedFilePath); |
||||
| 141 | } |
||||
| 142 | |||||
| 143 | $uploadfilesNames = collect(preg_grep('~\.('.$fileTypes.')$~', scandir($uploadedFilePath))); |
||||
|
0 ignored issues
–
show
It seems like
scandir($uploadedFilePath) can also be of type false; however, parameter $input of preg_grep() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 144 | $recordedfilesNames = collect(preg_grep('~\.('.$fileTypes.')$~', scandir($recordedFilePath))); |
||||
| 145 | |||||
| 146 | $data = [ |
||||
| 147 | 'uploadfilesNames' => $uploadfilesNames, |
||||
| 148 | 'recordedfilesNames' => $recordedfilesNames, |
||||
| 149 | ]; |
||||
| 150 | |||||
| 151 | return $data; |
||||
| 152 | } |
||||
| 153 | } |
||||
| 154 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths