From 7d1406ee5cfa18f45505362e246f4fb7193df4ea Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Fri, 12 Aug 2022 07:53:27 +0000 Subject: [PATCH] - array/string Helpers: Laravel Convert old array and string helpers into their modern class-based methods. - Use Laravel Carbon: Laravel provides an Illuminate\Support\Carbon class which wraps the underlying Carbon class. By using this class, you gain access to some additional testing methods and create separation between your code and underlying dependencies. --- app/Http/Controllers/Oai/RequestController.php | 2 +- app/Http/Controllers/Publish/EditorController.php | 2 +- app/Http/Controllers/Publish/ReviewController.php | 2 +- app/Library/Util/SearchResultMatch.php | 2 +- app/Library/Xml/DatasetExtension.php | 2 +- app/Library/Xml/Strategy.php | 4 ++-- app/Models/Dataset.php | 2 +- app/Rules/RdrFilesize.php | 3 ++- database/seeders/CollectionsTableSeeder.php | 2 +- database/seeders/LanguagesTableSeeder.php | 2 +- database/seeders/MessagesTableSeeder.php | 2 +- database/seeders/MimetypeTableSeeder.php | 2 +- database/seeders/ProjectsTableSeeder.php | 2 +- database/seeders/RolesTableSeeder.php | 2 +- resources/views/settings/document/_form.blade.php | 2 +- resources/views/workflow/review/index.blade.php | 2 +- 16 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Oai/RequestController.php b/app/Http/Controllers/Oai/RequestController.php index 759a980..329ee0a 100644 --- a/app/Http/Controllers/Oai/RequestController.php +++ b/app/Http/Controllers/Oai/RequestController.php @@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use \Exception; -// use Carbon\Carbon; +// use Illuminate\Support\Carbon; use \Illuminate\Support\Carbon; class RequestController extends Controller diff --git a/app/Http/Controllers/Publish/EditorController.php b/app/Http/Controllers/Publish/EditorController.php index 9991c77..937599f 100644 --- a/app/Http/Controllers/Publish/EditorController.php +++ b/app/Http/Controllers/Publish/EditorController.php @@ -18,7 +18,7 @@ use App\Models\User; use App\Rules\RdrFilesize; use App\Rules\RdrFiletypes; // use Illuminate\View\View; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; diff --git a/app/Http/Controllers/Publish/ReviewController.php b/app/Http/Controllers/Publish/ReviewController.php index 53f0276..102d40f 100644 --- a/app/Http/Controllers/Publish/ReviewController.php +++ b/app/Http/Controllers/Publish/ReviewController.php @@ -82,7 +82,7 @@ class ReviewController extends Controller $fieldval = $fieldValue->{$property_name}; $value = $value . $fieldName . ": " . $fieldval . "; "; } - } elseif ($fieldValue instanceof \Carbon\Carbon) { + } elseif ($fieldValue instanceof \Illuminate\Support\Carbon) { $value = $value . " Year " . $fieldValue->year; $value = $value . " Month " . $fieldValue->month; $value = $value . " Day " . $fieldValue->day; diff --git a/app/Library/Util/SearchResultMatch.php b/app/Library/Util/SearchResultMatch.php index 581da6e..813cf7e 100644 --- a/app/Library/Util/SearchResultMatch.php +++ b/app/Library/Util/SearchResultMatch.php @@ -1,7 +1,7 @@ _mapModelAttributes($value, $dom, $childNode); - } elseif ($value instanceof \Carbon\Carbon) { + } elseif ($value instanceof \Illuminate\Support\Carbon) { $this->_mapDateAttributes($value, $dom, $childNode); } elseif (is_array($value)) { $this->_mapArrayAttributes($value, $dom, $childNode); @@ -181,7 +181,7 @@ class Strategy return $dom->createElement($fieldName); } - protected function _mapDateAttributes(\Carbon\Carbon $model, DOMDocument $dom, \DOMNode $rootNode) + protected function _mapDateAttributes(\Illuminate\Support\Carbon $model, DOMDocument $dom, \DOMNode $rootNode) { $rootNode->setAttribute("Year", $model->year); $rootNode->setAttribute("Month", $model->month); diff --git a/app/Models/Dataset.php b/app/Models/Dataset.php index 7926acf..4272ed7 100644 --- a/app/Models/Dataset.php +++ b/app/Models/Dataset.php @@ -15,7 +15,7 @@ use App\Models\Title; use App\Models\User; use App\Models\XmlCache; use App\Models\DatasetIdentifier; -use Carbon\Carbon; +use Illuminate\Support\Carbon; // use App\Models\GeolocationBox; use Illuminate\Database\Eloquent\Model; diff --git a/app/Rules/RdrFilesize.php b/app/Rules/RdrFilesize.php index 4d0ad75..4d710fa 100644 --- a/app/Rules/RdrFilesize.php +++ b/app/Rules/RdrFilesize.php @@ -2,6 +2,7 @@ namespace App\Rules; +use Illuminate\Support\Arr; use Illuminate\Contracts\Validation\Rule; use Illuminate\Support\Facades\Config; @@ -102,7 +103,7 @@ class RdrFilesize implements Rule private function getSize($attribute, $value) { if (is_numeric($value) && $hasNumeric) { - return array_get($this->data, $attribute); + return Arr::get($this->data, $attribute); } elseif (is_array($value)) { return count($value); } elseif ($value instanceof File) { diff --git a/database/seeders/CollectionsTableSeeder.php b/database/seeders/CollectionsTableSeeder.php index 1c2332a..65bb26b 100644 --- a/database/seeders/CollectionsTableSeeder.php +++ b/database/seeders/CollectionsTableSeeder.php @@ -2,7 +2,7 @@ namespace Database\Seeders; -// use Carbon\Carbon; +// use Illuminate\Support\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; diff --git a/database/seeders/LanguagesTableSeeder.php b/database/seeders/LanguagesTableSeeder.php index 686bb81..ba3fca1 100644 --- a/database/seeders/LanguagesTableSeeder.php +++ b/database/seeders/LanguagesTableSeeder.php @@ -2,7 +2,7 @@ namespace Database\Seeders; -// use Carbon\Carbon; +// use Illuminate\Support\Carbon; // use Database\DisableForeignKeys; // use Database\TruncateTable; use Illuminate\Database\Seeder; diff --git a/database/seeders/MessagesTableSeeder.php b/database/seeders/MessagesTableSeeder.php index 881f81f..81e16af 100644 --- a/database/seeders/MessagesTableSeeder.php +++ b/database/seeders/MessagesTableSeeder.php @@ -2,7 +2,7 @@ namespace Database\Seeders; -use Carbon\Carbon; +use Illuminate\Support\Carbon; // use Database\DisableForeignKeys; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; diff --git a/database/seeders/MimetypeTableSeeder.php b/database/seeders/MimetypeTableSeeder.php index cbe1f1c..7c9b0fc 100644 --- a/database/seeders/MimetypeTableSeeder.php +++ b/database/seeders/MimetypeTableSeeder.php @@ -2,7 +2,7 @@ namespace Database\Seeders; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; diff --git a/database/seeders/ProjectsTableSeeder.php b/database/seeders/ProjectsTableSeeder.php index 0b29150..4566169 100644 --- a/database/seeders/ProjectsTableSeeder.php +++ b/database/seeders/ProjectsTableSeeder.php @@ -2,7 +2,7 @@ namespace Database\Seeders; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; diff --git a/database/seeders/RolesTableSeeder.php b/database/seeders/RolesTableSeeder.php index 512fed6..991ff41 100644 --- a/database/seeders/RolesTableSeeder.php +++ b/database/seeders/RolesTableSeeder.php @@ -2,7 +2,7 @@ namespace Database\Seeders; -use Carbon\Carbon; +use Illuminate\Support\Carbon; // use Database\DisableForeignKeys; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; diff --git a/resources/views/settings/document/_form.blade.php b/resources/views/settings/document/_form.blade.php index 69b01d9..d632bb5 100644 --- a/resources/views/settings/document/_form.blade.php +++ b/resources/views/settings/document/_form.blade.php @@ -93,7 +93,7 @@ {{--
{!! Form::label('licenses[]', 'Licenses..') !!} - {!! Form::select('licenses[]', $options, array_pluck($document->licenses, 'id'), ['multiple' ]) !!} + {!! Form::select('licenses[]', $options, Arr::pluck($document->licenses, 'id'), ['multiple' ]) !!}
--}}
diff --git a/resources/views/workflow/review/index.blade.php b/resources/views/workflow/review/index.blade.php index ff10199..bb8bcfd 100644 --- a/resources/views/workflow/review/index.blade.php +++ b/resources/views/workflow/review/index.blade.php @@ -48,7 +48,7 @@ {{-- @php $dateDiff = $dataset['server_date_modified']->addDays(14); - $remainingDays = Carbon\Carbon::now()->diffInDays($dateDiff, false); + $remainingDays = Illuminate\Support\Carbon::now()->diffInDays($dateDiff, false); @endphp --}} {{ $dataset->remaining_time . ' days' }}