Skip to content

Commit

Permalink
Implemented ADmad's suggestions about dependencies, phpunit, psalm an…
Browse files Browse the repository at this point in the history
…d phpstan isues
  • Loading branch information
Justin Ruiter committed Apr 4, 2024
1 parent 8eb7baf commit aed6bc4
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 58 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.2', '8.3']
php-version: ['8.1', '8.2', '8.3']
db-type: ['mysql', 'pgsql']
prefer-lowest: ['']
include:
- php-version: '8.3'
- php-version: '8.1'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'

Expand Down Expand Up @@ -61,14 +61,14 @@ jobs:
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
if [[ ${{ matrix.php-version }} == '8.3' && ${{ matrix.db-type }} == 'mysql' ]]; then
if [[ ${{ matrix.php-version }} == '8.1' && ${{ matrix.db-type }} == 'mysql' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '8.3' && matrix.db-type == 'mysql'
if: success() && matrix.php-version == '8.1' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v1

cs-stan:
Expand All @@ -81,7 +81,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: psalm:5.23.1, phpstan:1.10.65
Expand All @@ -90,8 +90,7 @@ jobs:
run: composer require cakephp/cakephp-codesniffer:^4.2

- name: Run phpcs
# Exclude Type hint sniffing, as it interferes with psalm
run: vendor/bin/phpcs --standard=CakePHP --exclude=CakePHP.Classes.ReturnTypeHint src/ tests/
run: vendor/bin/phpcs --standard=CakePHP src/ tests/

- name: Run psalm
if: success() || failure()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"require-dev": {
"cakephp/cakephp": "^5.0",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.1",
"phpunit/phpunit": "^10.5.5",
"ext-mbstring": "*",
"vimeo/psalm": "5.23.1",
"phpstan/phpstan": "1.10.65"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Slug Test Cases">
<testsuite name="Webservice Test Cases">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
3 changes: 2 additions & 1 deletion src/Datasource/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function __construct(array $config)

/**
* @param \Psr\SimpleCache\CacheInterface $cacher The cacher instance to use for query caching.
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function setCacher(CacheInterface $cacher): ConnectionInterface
{
Expand Down
48 changes: 26 additions & 22 deletions src/Datasource/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public function all(): ResultSetInterface
/**
* @param \Closure|array|string $fields The field configuration for the order by clause
* @param bool $overwrite Whether to overwrite the existing conditions
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function orderBy(Closure|array|string $fields, bool $overwrite = false): Query
{
Expand Down Expand Up @@ -374,7 +375,8 @@ public function toArray(): array
* Set the default repository object that will be used by this query.
*
* @param \Cake\Datasource\RepositoryInterface $repository The default repository object to use.
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function setRepository(RepositoryInterface $repository): Query
{
Expand All @@ -399,7 +401,7 @@ public function getRepository(): RepositoryInterface
/**
* Mark the query as create
*
* @return $this
* @return self
*/
public function create(): Query
{
Expand All @@ -411,7 +413,7 @@ public function create(): Query
/**
* Mark the query as read
*
* @return $this
* @return self
*/
public function read(): Query
{
Expand All @@ -423,7 +425,7 @@ public function read(): Query
/**
* Mark the query as update
*
* @return $this
* @return self
*/
public function update(): Query
{
Expand All @@ -435,7 +437,7 @@ public function update(): Query
/**
* Mark the query as delete
*
* @return $this
* @return self
*/
public function delete(): Query
{
Expand Down Expand Up @@ -468,8 +470,7 @@ public function clause(string $name): mixed
* Set the endpoint to be used
*
* @param \Muffin\Webservice\Model\Endpoint $endpoint The endpoint to use
* @return $this
* @psalm-suppress LessSpecificReturnStatement
* @return self
*/
public function setEndpoint(Endpoint $endpoint): Query
{
Expand All @@ -482,7 +483,6 @@ public function setEndpoint(Endpoint $endpoint): Query
* Set the endpoint to be used
*
* @return \Muffin\Webservice\Model\Endpoint
* @psalm-suppress MoreSpecificReturnType
*/
public function getEndpoint(): Endpoint
{
Expand All @@ -493,7 +493,7 @@ public function getEndpoint(): Endpoint
* Set the webservice to be used
*
* @param \Muffin\Webservice\Webservice\WebserviceInterface $webservice The webservice to use
* @return $this
* @return self
*/
public function setWebservice(WebserviceInterface $webservice): Query
{
Expand Down Expand Up @@ -549,8 +549,8 @@ public function aliasField(string $field, ?string $alias = null): array
* @param \Closure|array|string|null $conditions The list of conditions.
* @param array $types Not used, required to comply with QueryInterface.
* @param bool $overwrite Whether to replace previous queries.
* @return $this
* @psalm-suppress ImplementedReturnTypeMismatch Not the nicest solution, but wishing to keep the functionality backwards compatible
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function where(
Closure|array|string|null $conditions = null,
Expand All @@ -570,7 +570,7 @@ public function where(
*
* @param array|string $conditions The conditions to add with AND.
* @param array $types associative array of type names used to bind values to query
* @return $this
* @return self
* @see \Cake\Database\Query::where()
* @see \Cake\Database\Type
* @psalm-suppress PossiblyInvalidArgument
Expand All @@ -586,7 +586,7 @@ public function andWhere(string|array $conditions, array $types = []): Query
* Charge this query's action
*
* @param int $action Action to use
* @return $this
* @return self
*/
public function action(int $action): Query
{
Expand All @@ -607,7 +607,8 @@ public function action(int $action): Query
* @param int $num The page number you want.
* @param int|null $limit The number of rows you want in the page. If null
* the current limit clause will be used.
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function page(int $num, ?int $limit = null): Query
{
Expand Down Expand Up @@ -637,7 +638,8 @@ public function page(int $num, ?int $limit = null): Query
* ```
*
* @param ?int $limit number of records to be returned
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function limit(?int $limit): Query
{
Expand All @@ -650,7 +652,7 @@ public function limit(?int $limit): Query
* Set fields to save in resources
*
* @param \Closure|array|string $fields The field to set
* @return $this
* @return self
*/
public function set(Closure|array|string $fields): Query
{
Expand Down Expand Up @@ -688,7 +690,8 @@ public function offset(?int $offset): Query|QueryInterface
*
* @param \Cake\Database\ExpressionInterface|\Closure|array|string $fields fields to be added to the list
* @param bool $overwrite whether to reset order with field list or not
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function order(array|ExpressionInterface|Closure|string $fields, bool $overwrite = false): Query
{
Expand Down Expand Up @@ -880,7 +883,8 @@ public function jsonSerialize(): ResultSetInterface
*
* @param \Cake\Database\ExpressionInterface|\Closure|array|string|float|int $fields The list of fields to select from _source.
* @param bool $overwrite Whether or not to replace previous selections.
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function select(ExpressionInterface|Closure|array|string|int|float $fields, bool $overwrite = false): Query
{
Expand Down Expand Up @@ -957,7 +961,7 @@ protected function decorateResults(iterable $result): ResultSetInterface
* @param \Closure|null $mapper The mapper function
* @param \Closure|null $reducer The reducing function
* @param bool $overwrite Set to true to overwrite existing map + reduce functions.
* @return $this
* @return self
* @see \Cake\Collection\Iterator\MapReduce for details on how to use emit data to the map reducer.
*/
public function mapReduce(?Closure $mapper = null, ?Closure $reducer = null, bool $overwrite = false): Query
Expand Down Expand Up @@ -1013,7 +1017,7 @@ public function isEagerLoaded(): bool
* passed, the current configured query `_eagerLoaded` value is returned.
*
* @param bool $value Whether to eager load.
* @return $this
* @return self
*/
public function eagerLoaded(bool $value): Query
{
Expand Down Expand Up @@ -1062,7 +1066,7 @@ public function eagerLoaded(bool $value): Query
*
* @param \Closure|null $formatter The formatting function
* @param int|bool $mode Whether to overwrite, append or prepend the formatter.
* @return $this
* @return self
* @throws \InvalidArgumentException
*/
public function formatResults(?Closure $formatter = null, int|bool $mode = self::APPEND): Query
Expand Down
2 changes: 1 addition & 1 deletion src/Datasource/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function valid(): bool
* Part of Iterator interface.
*
* @return int
* @psalm-suppress ImplementedReturnTypeMismatch This seems to be implemented with the key as an integer everywhere **/
*/
public function key(): int
{
return $this->_index;
Expand Down
12 changes: 8 additions & 4 deletions src/Datasource/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public function name(): string
*
* @param string $name The name of the column
* @param array|string $attrs The attributes for the column.
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function addColumn(string $name, array|string $attrs): Schema
{
Expand Down Expand Up @@ -219,7 +220,8 @@ public function hasColumn(string $name): bool
* If the column is not defined in the table, no error will be raised.
*
* @param string $name The name of the column
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function removeColumn(string $name): Schema
{
Expand All @@ -233,7 +235,8 @@ public function removeColumn(string $name): Schema
*
* @param string $name Column name
* @param string $type Type to set for the column
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function setColumnType(string $name, string $type): Schema
{
Expand Down Expand Up @@ -358,7 +361,8 @@ public function getPrimaryKey(): array
* Set the schema options for an endpoint
*
* @param array<string, mixed> $options Array of options to set
* @return $this
* @return self
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function setOptions(array $options): Schema
{
Expand Down
Loading

0 comments on commit aed6bc4

Please sign in to comment.