PHP code example of raul338 / cakephp-phpstan-extensions

1. Go to this page and download the library: Download raul338/cakephp-phpstan-extensions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raul338 / cakephp-phpstan-extensions example snippets


$query = $this->Users->findAllByUsername('joebob');

/**
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 */
public class UsersTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->addBehavior('Timestamp');
    }
}
// somewhere else - phpstan will know its the Timestamp touch method
$this->Users->touch($user);

public function add()
{
    // phpstan will know action() is a AddAction instead of BaseAction
    $this->Crud->action()->saveOptions([]);

    // phpstan will know it is a \Crud\Listener\RelatedModelsListener
    $this->Crud->listener('relatedModels')->relatedModels(true);
}

public function custom()
{
    $this->Crud->mapAction('custom', 'Crud.Index');
    /** @var \Crud\Action\IndexAction */
    $action = $this->Crud->action();
}

$this->Crud->on('beforePaginate', function (Event $event) {
    $query = $event->getSubject()->query;
    $query->where([ /** ... */]);
});