Skip to content

Commit

Permalink
Merge pull request #6 from UseMuffin/cake-5
Browse files Browse the repository at this point in the history
Cake 5
  • Loading branch information
ADmad authored Sep 27, 2023
2 parents a6d7c06 + e411c93 commit f34ba8a
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 137 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ end_of_line = crlf

[*.yml]
indent_style = space
indent_size = 2
indent_size = 2

[*.neon]
indent_style = tab
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.semver export-ignore
.github export-ignore
phpunit.xml.dist export-ignore
.travis.yml export-ignore
tests export-ignore
psalm.xml export-ignore
psalm-baseline.xml export-ignore
phpstan.neon export-ignore
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- '*'

permissions:
contents: read

jobs:
testsuite:
uses: ADmad/.github/.github/workflows/testsuite-with-db.yml@master
secrets: inherit

cs-stan:
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
secrets: inherit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/composer.lock
/plugins
/vendor
.phpunit.cache
.phpunit.result.cache
65 changes: 0 additions & 65 deletions .travis.yml

This file was deleted.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Orderly

[![Build Status](https://img.shields.io/travis/UseMuffin/Orderly/master.svg?style=flat-square)](https://travis-ci.org/UseMuffin/Orderly)
[![Coverage](https://img.shields.io/coveralls/github/UseMuffin/Orderly?style=flat-square)](https://coveralls.io/github/UseMuffin/Orderly)
[![Build Status](https://img.shields.io/github/actions/workflow/status/UseMuffin/Orderly/ci.yml?style=flat-square
&branch=master)](https://github.com/UseMuffin/Orderly/actions/workflows/ci.yml?query=branch%3Amaster)
[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Orderly/master?style=flat-square
)](https://app.codecov.io/gh/UseMuffin/Orderly)
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/orderly.svg?style=flat-square)](https://packagist.org/packages/muffin/orderly)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)

Expand All @@ -23,8 +25,7 @@ bin/cake plugin load Muffin/Orderly

## What is does

Orderly allow you to set default `ORDER` clause for your table queries, similar
to the functionality provided by `Model::$order` property of CakePHP 2.x.
Orderly allow you to set default `ORDER` clause for your table's `SELECT` queries.

## Usage

Expand All @@ -38,7 +39,7 @@ $this->addBehavior('Muffin/Orderly.Orderly');
$this->addBehavior('Muffin/Orderly.Orderly', ['order' => $this->aliasField('field_name')]);
```

Value for `order` key can any valid value that `\Cake\ORM\Query::order()` takes.
Value for `order` key can any valid value that `\Cake\ORM\Query::orderBy()` takes.
The default order clause will only be applied to the primary query and when no
custom order clause has already been set for the query.

Expand Down Expand Up @@ -97,4 +98,4 @@ Copyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT Lic
[composer]:http://getcomposer.org
[mit]:http://www.opensource.org/licenses/mit-license.php
[muffin]:http://usemuffin.com
[standards]:http://book.cakephp.org/3/en/contributing/cakephp-coding-conventions.html
[standards]:http://book.cakephp.org/5/en/contributing/cakephp-coding-conventions.html
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"source": "https://github.com/usemuffin/orderly"
},
"require": {
"cakephp/orm": "^4.0"
"cakephp/orm": "^5.0"
},
"require-dev": {
"cakephp/cakephp": "^4.0",
"phpunit/phpunit": "~8.5.0"
"cakephp/cakephp": "^5.0",
"phpunit/phpunit": "^10.1"
},
"autoload": {
"psr-4": {
Expand All @@ -46,5 +46,11 @@
"Muffin\\Orderly\\Test\\": "tests",
"Cake\\Test\\Fixture\\": "vendor/cakephp/cakephp/tests/Fixture"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
level: 7
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
bootstrapFiles:
- tests/bootstrap.php
paths:
- src
33 changes: 11 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="./tests/bootstrap.php"
colors="true"
stopOnFailure="false"
>

<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="Orderly Test Cases">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>

<filter>
<whitelist>
<extensions>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>
<php>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
</php>
<source>
<include>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</include>
</source>
</phpunit>
8 changes: 0 additions & 8 deletions psalm-baseline.xml

This file was deleted.

3 changes: 2 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
19 changes: 11 additions & 8 deletions src/Model/Behavior/OrderlyBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use ArrayObject;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;

class OrderlyBehavior extends Behavior
{
/**
* Initialize behavior
*
* @param array $config Config
* @param array<string, mixed> $config Config
* @return void
*/
public function initialize(array $config): void
Expand All @@ -24,15 +24,15 @@ public function initialize(array $config): void
}

/**
* Add default order clause to query as necessary.
* Add the default order clause to the query as necessary.
*
* @param \Cake\Event\EventInterface $event Event
* @param \Cake\ORM\Query $query Query
* @param \Cake\ORM\Query\SelectQuery $query Query
* @param \ArrayObject $options Options
* @param bool $primary Boolean indicating whether it's primary query.
* @return void
*/
public function beforeFind(EventInterface $event, Query $query, ArrayObject $options, bool $primary)
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options, bool $primary): void
{
if ($query->clause('order')) {
return;
Expand All @@ -44,15 +44,15 @@ public function beforeFind(EventInterface $event, Query $query, ArrayObject $opt
empty($config['callback'])
|| call_user_func($config['callback'], $query, $options, $primary)
) {
$query->order($config['order']);
$query->orderBy($config['order']);
}
}
}

/**
* Normalize configuration.
*
* @param array $orders Orders config
* @param array<string, mixed> $orders Orders config
* @return void
*/
protected function _normalizeConfig(array $orders): void
Expand All @@ -64,7 +64,10 @@ protected function _normalizeConfig(array $orders): void
}

$default = [
'order' => $this->_table->aliasField($this->_table->getDisplayField()),
'order' => array_map(
$this->_table->aliasField(...),
(array)$this->_table->getDisplayField()
),
'callback' => null,
];

Expand Down
12 changes: 6 additions & 6 deletions src/Plugin.php → src/OrderlyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@

use Cake\Core\BasePlugin;

class Plugin extends BasePlugin
class OrderlyPlugin extends BasePlugin
{
/**
* The name of this plugin
*
* @var string
* @var string|null
*/
protected $name = 'Orderly';
protected ?string $name = 'Orderly';

/**
* Do bootstrapping or not
*
* @var bool
*/
protected $bootstrapEnabled = false;
protected bool $bootstrapEnabled = false;

/**
* Load routes or not
*
* @var bool
*/
protected $routesEnabled = false;
protected bool $routesEnabled = false;

/**
* Console middleware
*
* @var bool
*/
protected $consoleEnabled = false;
protected bool $consoleEnabled = false;
}
Loading

0 comments on commit f34ba8a

Please sign in to comment.