1. Go to this page and download the library: Download cakedc/cakephp-phpstan 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/ */
cakedc / cakephp-phpstan example snippets
//Now PHPStan know that \App\Models\Table\NotesTable::get returns \App\Model\Entity\Note
$note = $this->Notes->get(1);
$note->note = 'My new note';//No error
//Now PHPStan know that \App\Models\Table\NotesTable::newEntity returns \App\Model\Entity\Note
$note = $this->Notes->newEntity($data);
$note->note = 'My new note new entity';//No error
//Now PHPStan know that \App\Models\Table\NotesTable::newEmptyEntity returns \App\Model\Entity\Note
$note = $this->Notes->newEmptyEntity($data);
$note->note = 'My new note new empty entity';//No error
//Now PHPStan know that \App\Models\Table\NotesTable::findOrCreate returns \App\Model\Entity\Note
$note = $this->Notes->findOrCreate($data);
$note->note = 'My entity found or created';//No error
//Now PHPStan know that \App\Models\Table\NotesTable::newEntities returns \App\Model\Entity\Note[]
$notes = $this->Notes->newEntities($data);
foreach ($notes as $note) {
$note->note = 'My new note';//No error
}
//Now PHPStan know that \App\Models\Table\NotesTable::get returns \App\Model\Entity\Note
$note = $this->Notes->get(1);
$notes = $this->Notes->newEntities($data);
//Since PHPStan knows the type of $note, these methods call use the same type as return type:
$note = $this->Notes->patchEntity($note, $data);
$text = $note->note;//No error.
$note = $this->Notes->save($note);
$text = $note->note;//No error.
$note = $this->Notes->saveOrFail($note);
$text = $note->note;//No error.
//Since PHPStan knows the type of $notes, these methods call use the same type as return type:
$notes = $this->Notes->patchEntities($notes);
$notes = $this->Notes->saveMany($notes);
$notes = $this->Notes->saveManyOrFail($notes);
$notes = $this->Notes->deleteMany($notes);
$notes = $this->Notes->deleteManyOrFail($notes);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.