-
Notifications
You must be signed in to change notification settings - Fork 0
Laravel PreShift #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel PreShift #115
Conversation
PHP 5.5.9 adds the new static `class` property which provides the fully qualified class name. This is preferred over using strings for class names since the `class` property references are checked by PHP.
|
ℹ️ Shift detected you are currently on Laravel 11.0. This is the latest version of Laravel. As such, you do not need to upgrade Laravel. You may consider running the Laravel Fixer to ensure your application follows the latest Laravel conventions, or some of the automation available within the Shift CLI. |
|
|
|
ℹ️ All Shifts bump core Laravel dependencies as well as popular community packages. However, some packages may have their own upgrade steps. To make review easier, Shift will note packages which are bumped major versions, as well as packages which were not bumped or potentially abandoned. The following dependencies are not updated by Shift and may be incompatible. Before upgrading, you should check their compatibility, and, if necessary, look for an alternative. |
WalkthroughThis pull request refactors multiple parts of the codebase by replacing string literals that represent class names with PHP’s Changes
Possibly related PRs
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
app/Nova/Actions/ImportBarangFromSpesifikasiKerangkaAcuan.php (1)
30-30: LGTM! Consider refactoring repeated class reference.The changes to use
::classconstant improve type safety. Since\App\Models\PembelianPersediaan::classis used twice, consider storing it in a class constant to maintain DRY principles.class ImportBarangFromSpesifikasiKerangkaAcuan extends Action { use InteractsWithQueue, Queueable; + private const PERSEDIAAN_TYPE = \App\Models\PembelianPersediaan::class; + public $name = 'Impor dari KAK'; public function handle(ActionFields $fields, Collection $models) { $model = $models->first(); BarangPersediaan::where('barang_persediaanable_id', $model->id) - ->where('barang_persediaanable_type', \App\Models\PembelianPersediaan::class) + ->where('barang_persediaanable_type', self::PERSEDIAAN_TYPE) ->delete(); // ... $barang->barang_persediaanable_id = $model->id; - $barang->barang_persediaanable_type = \App\Models\PembelianPersediaan::class; + $barang->barang_persediaanable_type = self::PERSEDIAAN_TYPE;Also applies to: 41-41
app/Providers/CalendarDataProvider.php (1)
93-94: Consider simplifying the ternary operation.The current implementation can be made more concise using Laravel's model relationship features.
- $pj = $event->model()->daftar_kegiatanable_type == \App\Models\UnitKerja::class ? UnitKerja::find($event->model()->daftar_kegiatanable_id)->unit : User::find($event->model()->daftar_kegiatanable_id)->name; - $event->notes('PJ: '.$pj); + $pj = $event->model()->daftar_kegiatanable_type == \App\Models\UnitKerja::class + ? $event->model()->daftar_kegiatanable->unit + : $event->model()->daftar_kegiatanable->name; + $event->notes('PJ: ' . $pj);app/Models/BarangPersediaan.php (1)
41-41: LGTM! Good use of class constants for type checking.The replacement of string literals with
::classconstants improves type safety and makes the code more maintainable. This change aligns well with Laravel best practices.Consider extracting these type checks into constants or methods to reduce repetition and improve readability:
class BarangPersediaan extends Model { + private const TYPE_PEMBELIAN = \App\Models\PembelianPersediaan::class; + private const TYPE_PERMINTAAN = \App\Models\PermintaanPersediaan::class; + private const TYPE_KELUAR = \App\Models\PersediaanKeluar::class; + private const TYPE_MASUK = \App\Models\PersediaanMasuk::class; + + private function isPembelianPersediaan(): bool + { + return $this->barang_persediaanable_type === self::TYPE_PEMBELIAN; + } // ... existing code ... - if ($persediaan->barang_persediaanable_type == \App\Models\PembelianPersediaan::class) + if ($persediaan->isPembelianPersediaan())Also applies to: 52-52, 57-57, 61-61
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
app/Helpers/Cetak.php(3 hunks)app/Helpers/Helper.php(2 hunks)app/Models/BarangPersediaan.php(2 hunks)app/Models/PersediaanKeluar.php(1 hunks)app/Models/PersediaanMasuk.php(1 hunks)app/Nova/Actions/ImportBarangFromSpesifikasiKerangkaAcuan.php(2 hunks)app/Nova/Actions/ImportMasterPersediaan.php(1 hunks)app/Nova/Lenses/FormRencanaAksi.php(1 hunks)app/Nova/Lenses/RealisasiAnggaran.php(1 hunks)app/Nova/Lenses/RekapHonorMitra.php(1 hunks)app/Nova/Lenses/RencanaPenarikanDana.php(1 hunks)app/Nova/Metrics/JumlahKegiatan.php(1 hunks)app/Nova/Metrics/JumlahMitra.php(1 hunks)app/Nova/Metrics/KesesuaianSbml.php(1 hunks)app/Nova/Metrics/MetricKeberadaan.php(1 hunks)app/Nova/Metrics/SerapanAnggaran.php(1 hunks)app/Providers/CalendarDataProvider.php(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- app/Nova/Metrics/JumlahKegiatan.php
- app/Nova/Lenses/FormRencanaAksi.php
🔇 Additional comments (19)
app/Models/PersediaanMasuk.php (1)
34-34: LGTM! Good use of ::class constant.The change from string literal to
::classconstant improves type safety and maintainability. This is a recommended Laravel practice that enables better IDE support and refactoring capabilities.app/Models/PersediaanKeluar.php (1)
34-34: LGTM! Consistent use of ::class constant.The change maintains consistency with PersediaanMasuk model and follows Laravel best practices for type safety.
app/Nova/Metrics/JumlahMitra.php (1)
31-31: LGTM! Verify other filter types.The change to use
::classconstant for BulanFilter is correct. Note that line 30 still uses a string literal for 'Select:jenis_kontrak_id' - this appears to be a different type of filter, but it might be worth verifying if this is intentional.✅ Verification successful
🏁 Script executed:
#!/bin/bash # Search for other uses of Select filters to confirm the pattern rg -l "Select:" --type phpLength of output: 1376
It seems that several files in the repository continue to use the string literal notation for select filters. In particular, the change in
app/Nova/Metrics/JumlahMitra.phpto use the::classconstant forBulanFilteris in line with other filter types that use the::classformat. However, the use of the string literal forSelect:jenis_kontrak_idappears consistent with other parts of the codebase, suggesting that this is intentional.Actionable Feedback:
- The change for
BulanFilteris correct.- The string literal for
Select:jenis_kontrak_idis likely intentional, as similar filter patterns are used elsewhere.app/Nova/Metrics/MetricKeberadaan.php (2)
64-64: LGTM! Type-safe class reference.The change from string literal to
::classconstant improves type safety and maintainability.
41-41: LGTM! Consistent use of type-safe class references.All string literal class references have been replaced with
::classconstants in the model's event handlers, improving type safety and maintainability.Also applies to: 52-52, 57-57, 61-61, 66-66, 70-70
app/Nova/Actions/ImportMasterPersediaan.php (1)
62-62: LGTM! Type-safe morphable type reference.The change from string literal to
::classconstant for the morphable type improves type safety and maintainability.app/Nova/Metrics/KesesuaianSbml.php (1)
24-25: LGTM! Type-safe filter class reference.The change from string literal to
::classconstant forBulanFilterimproves type safety. The remaining string literal for'Select:jenis_kontrak_id'appears to be a different type of filter and is correctly left as is.✅ Verification successful
🏁 Script executed:
#!/bin/bash # Description: Verify if 'Select:jenis_kontrak_id' is a special filter type that should remain as a string literal # Search for other usages of Select filter type rg -l "Select:" --type phpLength of output: 1376
LGTM!
The usage of the string literal'Select:jenis_kontrak_id'follows the established pattern for select-type filters in the codebase, as verified by multiple instances across different files. The change to use the::classconstant forBulanFilterindeed improves type safety, while the string literal remains appropriately applied for its specialized purpose.app/Nova/Metrics/SerapanAnggaran.php (1)
40-41: LGTM! Good use of ::class constants.The changes improve type safety by replacing string literals with class constants, making the code more maintainable and less prone to errors.
app/Nova/Lenses/RencanaPenarikanDana.php (1)
42-42: LGTM! Good use of ::class constant.The change improves type safety by replacing the string literal with a class constant, making the code more maintainable and less prone to errors.
app/Providers/CalendarDataProvider.php (1)
93-93: LGTM! Good use of ::class constant.The change improves type safety by replacing the string literal with a class constant, making the code more maintainable and less prone to errors.
app/Nova/Lenses/RekapHonorMitra.php (1)
43-44: LGTM! Good use of ::class constant.The change improves type safety by replacing the string literal with a class constant, making the code more maintainable and less prone to errors. The string literal for the select filter is correctly left unchanged as it represents a different use case.
app/Nova/Lenses/RealisasiAnggaran.php (1)
47-47: LGTM! Good use of::classsyntax.The change from string literal to
::classsyntax improves type safety and maintainability. This is a Laravel best practice as it provides better IDE support and refactoring capabilities.app/Helpers/Cetak.php (2)
97-97: LGTM! Good use of::classsyntax in update queries.The changes improve type safety by using
::classinstead of string literals for model class references in database update queries.Also applies to: 104-104
681-681: LGTM! Good use of::classsyntax in where clauses.The changes improve type safety by using
::classinstead of string literals for model class references in database where clauses.Also applies to: 710-710
app/Helpers/Helper.php (4)
1128-1135: LGTM! Good use of::classsyntax in match expressions (part 1).The changes improve type safety by using
::classinstead of string literals for model class references in match expressions.
1140-1147: LGTM! Good use of::classsyntax in match expressions (part 2).The changes improve type safety by using
::classinstead of string literals for model class references in match expressions.
1158-1160: LGTM! Good use of::classsyntax in match expressions (part 3).The changes improve type safety by using
::classinstead of string literals for model class references in match expressions.Also applies to: 1165-1168
1881-1881: LGTM! Good use of::classsyntax in type comparison.The change improves type safety by using
::classinstead of string literals for model class reference in type comparison.app/Models/BarangPersediaan.php (1)
66-66: LGTM! Consistent use of class constants.The changes in the
deletingevent handler maintain consistency with thesavingevent handler, providing the same benefits of type safety and maintainability.Also applies to: 70-70
This pull request contains changes from the Laravel PreShift to give you a feel for upgrading with Shift. All Shifts open a pull request with the changes in nice, atomic commits. This allows you to review each change in isolation.
Shifts also leave comments with details on any additional manual changes you may need to make, or changes you may want to implement to follow the latest Laravel conventions.
To complete a Shift:
shift-139668branchcomposer update(if the scripts fail, try with--no-scripts)If you have any issue with your Shift, never hesitate to contact [email protected], or check out the Human Shifts for more hands-on support.
Summary by CodeRabbit