Skip to content
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 Linter #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Laravel Linter #5

wants to merge 1 commit into from

Conversation

Selembung
Copy link
Owner

This pull request includes changes and recommendations for crafting your application "The Laravel Way". Feel free to commit any additional changes to the shift-40914 branch.

Before merging, you need to:

  • Checkout the shift-40914 branch
  • Review all pull request comments for additional changes
  • Thoroughly test your application

If you need help with your upgrade, check out the Human Shifts. You may also join the Shifty Coders Slack workspace to level-up your Laravel skills.

@Selembung
Copy link
Owner Author

⚠️ Shift found uses of the old array() syntax. Laravel adopted the short array syntax [] since it became available in PHP 5.4.

@Selembung
Copy link
Owner Author

⚠️ Shift found instances of string based class references. Laravel adopted the ::class static property since it became available in PHP 5.5. You should update your code to use references like App\SomeModel::class instead of strings like 'App\SomeModel'.

@Selembung
Copy link
Owner Author

⚠️ The following files reference Laravel facades through the global namespace. For example, you're referencing \DB or importing use DB. Instead import Illuminate\Support\Facades\DB and reference DB.

While global references are allowed through aliases, you should import the facade explicitly. This can improve clarity not only for developers, but static analysis used by your IDE.

  • app/Helper.php
  • app/Http/Controllers/AcademicYearController.php
  • app/Http/Controllers/CourseController.php
  • app/Http/Controllers/CourseHourController.php
  • app/Http/Controllers/CourseScheduleController.php
  • app/Http/Controllers/CourseScheduleController.php
  • app/Http/Controllers/CurriculumController.php
  • app/Http/Controllers/CurriculumController.php
  • app/Http/Controllers/HomeController.php
  • app/Http/Controllers/HomeroomTeacherController.php
  • app/Http/Controllers/HomeroomTeacherController.php
  • app/Http/Controllers/KhsController.php
  • app/Http/Controllers/KrsController.php
  • app/Http/Controllers/MajorController.php
  • app/Http/Controllers/NilaiController.php
  • app/Http/Controllers/NilaiController.php
  • app/Http/Controllers/RombelController.php
  • app/Http/Controllers/RombelController.php
  • app/Http/Controllers/RoomController.php
  • app/Http/Controllers/ScoreController.php
  • app/Http/Controllers/ScoreController.php
  • app/Http/Controllers/StudentController.php
  • app/Http/Controllers/StudentController.php
  • app/Http/Controllers/TeacherController.php
  • app/Http/Controllers/TeacherController.php

@Selembung
Copy link
Owner Author

⚠️ The following classes do not extend the standard Laravel Model and Controller class. This may add complexity which makes your application harder to upgrade. Often a trait can be used instead of inheritance. You should review the following classes:

  • app/Helper.php

@Selembung
Copy link
Owner Author

⚠️ The following controllers contain actions outside of the 7 resource actions (index, create, store, show, edit, update, destroy). For more details, review the docs or watch Cruddy by Design to see if you can rework these into resource controllers.

  • app/Http/Controllers/AcademicYearController.php
  • app/Http/Controllers/CourseController.php
  • app/Http/Controllers/CourseHourController.php
  • app/Http/Controllers/CourseScheduleController.php
  • app/Http/Controllers/CurriculumController.php
  • app/Http/Controllers/HomeController.php
  • app/Http/Controllers/HomeroomTeacherController.php
  • app/Http/Controllers/KhsController.php
  • app/Http/Controllers/KrsController.php
  • app/Http/Controllers/LogActivityController.php
  • app/Http/Controllers/MajorController.php
  • app/Http/Controllers/NilaiController.php
  • app/Http/Controllers/ProfileController.php
  • app/Http/Controllers/RombelController.php
  • app/Http/Controllers/RoomController.php
  • app/Http/Controllers/ScoreController.php
  • app/Http/Controllers/StudentController.php
  • app/Http/Controllers/TeacherController.php

@Selembung
Copy link
Owner Author

⚠️ Shift found inline validation in the following controllers. Unless you require this level of control, you should use a Form Request to encapsulate this validation logic and keep your controller clean. You may automate this conversion with the Laravel Fixer.

  • app/Http/Controllers/KrsController.php

@Selembung
Copy link
Owner Author

⚠️ Shift detected the following HTTP components accessing the authenticated user through Auth::user(). Within these components, you can access the authenticated user through the request object as well. Doing so limits your dependencies by leveraging objects already available.

  • app/Http/Controllers/AcademicYearController.php
  • app/Http/Controllers/CourseController.php
  • app/Http/Controllers/CourseHourController.php
  • app/Http/Controllers/CourseScheduleController.php
  • app/Http/Controllers/CurriculumController.php
  • app/Http/Controllers/HomeController.php
  • app/Http/Controllers/HomeroomTeacherController.php
  • app/Http/Controllers/KhsController.php
  • app/Http/Controllers/KrsController.php
  • app/Http/Controllers/MajorController.php
  • app/Http/Controllers/NilaiController.php
  • app/Http/Controllers/RombelController.php
  • app/Http/Controllers/RoomController.php
  • app/Http/Controllers/ScoreController.php
  • app/Http/Controllers/StudentController.php
  • app/Http/Controllers/TeacherController.php

@Selembung
Copy link
Owner Author

⚠️ Shift found opportunities to use the built-in Blade directives like @auth in the following views:

  • resources/views/dashboard.blade.php
  • resources/views/layouts/headers/cards.blade.php
  • resources/views/layouts/navbars/sidebar.blade.php

@Selembung
Copy link
Owner Author

⚠️ To improve performance by caching your configuration, Laravel recommends you only use the env() helper within configuration files and use config() everywhere else. Shift found potential uses of env() in:

  • app/Http/Controllers/LogActivityController.php

@Selembung
Copy link
Owner Author

ℹ️ Laravel 8 reintroduced the app/Models folder by default. This is an optional change. Laravel and the artisan commands will automatically detect if you are using the app/Models folder or not.

If you wish to modernize your application to use the app/Models folder, you may run the Namespace Models Shift for free.

@Selembung
Copy link
Owner Author

ℹ️ Shift detected controller namespaces being set in your RouteServiceProvider. Laravel 8 began registering controllers using static class references instead of namespace prefixes and controller names.

You may automate this conversion using the Laravel Fixer or tasks within the Shift Workbench.

@Selembung
Copy link
Owner Author

⚠️ Shift found the following config files differ from the defaults. While you are welcome to customize your configuration, you should leverage ENV variables rather than hardcode values. If you find you're adding a lot of configuration options, consider creating a domain specific config file, such as core.php. Both will make app upgrades and deployments easier.

  • config/app.php
  • config/database.php
  • config/filesystems.php

@Selembung
Copy link
Owner Author

ℹ️ Shift detected your application only has the default tests. You can quickly start adding tests by using the Test Generator to automatically create the model factories, test classes, and sample tests cases for your Laravel application.

@Selembung
Copy link
Owner Author

⚠️ Laravel uses PSR-4 autoloading for the app/ folder. While you can configure your application to load these files within composer.json, all files under the app folder should be classes with a PSR-4 compliant namespace.

The following PHP files are missing a namespace:

  • app/Helper.php

@Selembung
Copy link
Owner Author

ℹ️ As noted, much of the lint detected above can be automatically fixed using the Laravel Fixer. Save yourself time and clean up your codebase quickly with this new Shift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants