lordsimal/cakephp-psalm

A psalm-plugin for CakePHP

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:psalm-plugin

dev-master 2022-01-02 21:52 UTC

This package is auto-updated.

Last update: 2022-01-02 21:52:40 UTC


README

Overview

This plugin provides correct return types for CakePHP specific methods in psalm.

Quickstart

Please refer to the full Psalm documentation for a more detailed guide on how to use Psalm in your project.

First you need to install the psalm base package and create a psalm.xml

composer require --dev vimeo/psalm
./vendor/bin/psalm --init

Next you will need to require this package and enable it in psalm

composer require --dev lordsimal/cakephp-psalm @dev
./vendor/bin/psalm-plugin enable lordsimal/cakephp-psalm

Finally you can try it out

./vendor/bin/psalm

How it works

Currently only the following return types are being corrected:

  • Cake\ORM\Locator\LocatorInterface::get()
  • Cake\ORM\Locator\LocatorAwareTrait::fetchTable()

The functionality for this can be found in src/Type/TableLocatorHandler.php

In there the getClassLikeNames() tells psalm on which classes it needs to change return types.

In the getMethodReturnType() we check which method is currently called and get the first argument value from that call.

With that value we get the "real" FQCN of the table which is returned in runtime and tell psalm to use that instead of the default Cake\ORM\Table.

Help needed

I would definitely appreciate help related to the following aspects of this plugin: