Pages

Showing posts with label phpstorm 2021. Show all posts
Showing posts with label phpstorm 2021. Show all posts

Sunday, July 11, 2021

PHPStorm Warning : Illegal string offset

 

Here is a comment about "Illegal string offset warning" I had in phpstorm.



I found the solution on StackOverflow : 

The error Illegal string offset 'whatever' in... generally means: you're trying to use a string as a full array.


In my case, I defined the following :

    /**
     * isAuthorized
     * @param string $user user authorized
     */
    public function isAuthorized($user)
    {
        // Autorisations
        // admin peut tout faire
        if ($user['role'] === 'admin') {
            return true;
        }

In fact, I made a mistake. The $user variable was defined in method comment as a string. But, $user is an array ! That's why I had this warning.

To avoid this warning, you have to change the type of the variable in method comment and a good practice is to add an "s" at the end of the variable name in order to identify easily the array variable. 


    /**
     * isAuthorized
     * @param array $users user authorized
     */
    public function isAuthorized($users)
    {
        // Autorisations
        // admin peut tout faire
        if ($users['role'] === 'admin') {
            return true;
        }


Sunday, July 4, 2021

PHPStorm Warning : Unresolved function or method $()

 I noticed this warning on my project : "Unresolved function or method $()"


I found the solution on the idea support (See https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002260719--jQuery-shortcut-underlined-as-unresolved-function-or-method-)

The solution :

Types resolving won't work when using minified library version (jquery-3.3.1.min.js), but downloading typings (@types/jquery) should work:
- in Settings | Languages & Frameworks | JavaScript | Libraries, press Download..., choose jquery from the list
Or, install it in your project:
- in terminal, cd to your project root folder
- run npm i @types/jquery  command



Version :
- phpstorm 2021.1.3



Saturday, June 26, 2021

Code inspection warning : Optional parameter is provided before required

I am used to inspect my source code and tried to solve warning. I've had the warning : Optional parameter is provided before required

This warning occured on this line  : 

function generateMenu($level=1, $label, $code, $labos) {

}

The explanation of this warning is quite simple.Optional parameters (with default values) always should be at the end, otherwise they are not optional !

So you have to write your function like this : 

function generateMenu($label, $code, $labos, $level=1) {

}

PHP Storm 2021.1.3
PHP 7.1

PlayConsole : suppression des warnings lors de la publication (minify, symbole de debogage...)

Lors de la publication des versions dans la PlayConsole, j'avais 2 warnings pour indiquer qu'il était possible de réduire et d'o...