![]() ![]() That's why I always add these 2 lines in PHPDoc for every class that extends Model - helps with non-static calls at very least (I'm trying to avoid magic calls conversion as much as possible). Laravel magic in action - it makes it work as if it available in Model class itself. Thing is: \Illuminate\Database\Eloquent\Model class does not have "where()" method - it comes from \Illuminate\Database\Eloquent\Builder. Back in the fragment above, the where method, which Account inherits from Model, is highlighted as not-found and generates a PHP warning in Phpstorm. In the Account.php file, I 'use' it with it's full namespace specifier. >class Account extends Model, which is specified. IDE helper will generate special file with such class defined + other stuff. There is no class with FQN "\Crypt" - it's handled dynamically at runtime by Laravel core by redirecting all into facede class. >For instance, in the code below, Crypt is highlighted as not defined. and here is where the aforementioned tools help. In such circumstances PhpStorm cannot resolve it on its own (especially since it does not know how Laravel functions under the hood as it does not provide any special support just for Laravel). while not always having it documented to full extent (e.g. Laravel uses tons (a lot) of magic (facedes and converting calls to non-existing static methods into instance ones). I'm using Laravel for a bit more than 1 year now - the above tools resolve almost everything. Once again, I thank you for your attention. This fills my code with warnings.Īnyway, that's a more modern example of the trouble I'm having with this, and I'd really like to understand how PhpStorm finds these things. ![]() In the retrieve method, $account is not highlighted, nor is Account::, and I can get to the Account class with ^B.Ĭlass Account extends Model, which is specified. In the createtestaccounts method, I call the static method Accounts::createTestAccounts() and Phpstorm does not highlight the class or the method, and I can ^B on the method name and go to it. Note that I use App\Model\AssistanceCheck\Accounts. $resource = new AccountResource($account) $account = Account::where( 'AccountID', $key ) Public function retrieve( $key, AccountRequest $request ) Return AccountResource::collection($accounts) $accounts = Account::createTestAccounts($agency->AgencyID, $number) If($agency->TestCustomer != 1) abort(403, 'Available for test customers only') The problem also exists whenever I use a Laravel model: user( ) Return Crypt::decrypt($this->attributes) Įlse if (in_array($key, $this->encrypted_fields) & !empty( $this->attributes ) ) See encrypted_date_fields ) & in_array( $key, $this->encrypted_date_fields ) & !empty( $this->attributes ) ) If we can resolve it there, it may lead to me resolving it in the legacy stuff.įor instance, in the code below, Crypt is highlighted as not defined. This is happening to me in a modern-day (Laravel) project as well. " - when I've said that I meant that it needs to be documented this way where it is used. "if in different files - maybe you need to typehint it with PHPDoc comment. but that requires more code change than adding or alike PHPDoc. There are other ways (IoC containers / Registry class / some static helper methods / passing dependent variables into function/class instead of relaying on global state) that are also more IDE friendly. So proper documenting with PHPDoc comments does help. PhpStorm does not really track such "variable defined here in one place and then somehow get used in include file there" usages. you do not need to use plain global variables at all. In modern frameworks where you have Dependency Injection + Location Containers etc. ![]() Otherwise - please make some simple test project (reduce your to just 3-4 or so simple files) that I can play with. ![]() If so - try marking such declarations with tag like WP does. so you are working with manual include/require management. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |