Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/updatesfrom 1 #7

Merged
merged 17 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.bat]
end_of_line = crlf

[*.yml]
indent_size = 2

[*.xml]
indent_size = 2

[Makefile]
indent_style = tab

[*.neon]
indent_style = tab
47 changes: 39 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
/tmp
/vendor
/.idea
composer.lock
.php_cs*
/coverage
/config/Migrations/schema-dump-default.lock
*.pyc
docs/_build
tmp
/composer.lock
/composer.phar
/phpunit.xml
*.diff
*.err
*.log
*.orig
*.rej
*.swo
*.swp
*.vi
*~
.idea/*
nbproject/*
.vscode
.DS_Store
.cache
.phpunit.cache
.project
.settings
.svn
errors.err
tags
node_modules
package-lock.json
/.phpunit.result.cache
/phpunit.phar
/config/Migrations/schema-dump-default.lock
/vendor/
/.idea/
/.phpunit.cache
/.ddev/
/nbproject/
/tools
/phpunit.xml
/webroot/css/style.css.map
/webroot/mix.js.map
/webroot/mix-manifest.json
.ddev/*
5 changes: 5 additions & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.32" installed="1.10.32" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
</phive>
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.2] 2024-03-01
- improved conde completion in `\CakeDC\Money\Money` class
- fixed issues reported by stan tools

## [2.0.1] - 2024-02-23
- Ported changes applied in tag `1.0.1`
- Ported changes applied in tag `1.0.1`

## [1.0.1] - 2024-02-23

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ It covers the following features:

## Versions and branches

| CakePHP | CakeDC Money Plugin | Notes |
| :-------------: | :------------------------: | :---- |
| ^5.0 | [2.x](https://github.com/cakedc/money/tree/2.next-cake5) | stable |
| ^4.5 | [1.x](https://github.com/cakedc/money/tree/1.next-cake4) | stable |
| ^4.0 | [0.0.1](https://github.com/cakedc/money/tree/0.0.1) | deprecated |
| CakePHP | CakeDC Money Plugin | Notes |
|:-------:|:--------------------------------------------------------:|:-----------|
| ^5.0 | [2.x](https://github.com/cakedc/money/tree/2.next-cake5) | stable |
| ^4.5 | [1.x](https://github.com/cakedc/money/tree/1.next-cake4) | stable |
| ^4.0 | [0.0.1](https://github.com/cakedc/money/tree/0.0.1) | deprecated |

## Installation

Expand Down
36 changes: 23 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0",
"moneyphp/money": "^4.0"
"moneyphp/money": "^4.0",
"ext-pdo": "*",
"ext-intl": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.1.0"
"phpunit/phpunit": "^10.1.0",
"cakephp/cakephp-codesniffer": "^5.1"
},
"autoload": {
"psr-4": {
Expand All @@ -24,19 +27,26 @@
},
"scripts": {
"check": [
"@test",
"@cs-check"
"@cs-check",
"@test"
],
"analyse": [
"@stan",
"cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
"phpstan": "tools/phpstan analyse",
"psalm": "tools/psalm --show-info=false",
"stan": [
"@phpstan",
"@psalm"
],
"cs-check": "phpcs -n -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
"test": "phpunit --stderr",
"stan": "phpstan analyse src/",
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.88 psalm/phar:~4.7.0 && mv composer.backup composer.json",
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml"
"phpstan-tests": "tools/phpstan analyze -c tests/phpstan.neon",
"phpstan-baseline": "tools/phpstan --generate-baseline",
"psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml",
"stan-setup": "phive install",
"test": "phpunit"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false
}
}
}
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="CakeDC/Money">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />
</ruleset>
2 changes: 2 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors:
15 changes: 9 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
includes:
- phpstan-baseline.neon
parameters:
level: 6
autoload_files:
- tests/bootstrap.php
ignoreErrors:
- '#Method CakeDC\\Auth\\Rbac\\Rules\\AbstractRule::_getTableFromRequest\(\) should return Cake\\ORM\\Table but returns Cake\\Datasource\\RepositoryInterface.#'
services:
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
bootstrapFiles:
- tests/bootstrap.php
paths:
- src/
3 changes: 2 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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"
autoloader="tests/bootstrap.php"
>
<projectFiles>
<directory name="src" />
Expand Down Expand Up @@ -42,7 +43,7 @@

<MoreSpecificReturnType errorLevel="info" />
<LessSpecificReturnStatement errorLevel="info" />
<TypeCoercion errorLevel="info" />
<!-- <TypeCoercion errorLevel="info" />-->

<PossiblyInvalidArrayAccess errorLevel="info" />
<PossiblyInvalidArrayOffset errorLevel="info" />
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* Copyright 2021, Cake Development Corporation (https://www.cakedc.com)
*
Expand All @@ -8,8 +10,6 @@
* @copyright Copyright 2021, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
declare(strict_types=1);

namespace CakeDC\Money\Controller;

use App\Controller\AppController as BaseController;
Expand Down
30 changes: 15 additions & 15 deletions src/Database/Type/MoneyType.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* Copyright 2021, Cake Development Corporation (https://www.cakedc.com)
*
Expand All @@ -14,8 +16,9 @@
use Cake\Database\Driver;
use Cake\Database\Type\BaseType;
use Cake\Database\TypeInterface;
use CakeDC\Money\Utility\MoneyUtil;
use CakeDC\Money\Money;
use CakeDC\Money\Utility\MoneyUtil;
use InvalidArgumentException;
use PDO;

/**
Expand All @@ -25,15 +28,14 @@
*/
class MoneyType extends BaseType implements TypeInterface
{

/**
* Casts given value from a database type to a PHP equivalent.
*
* @param mixed $value Value to be converted to PHP equivalent
* @param \Cake\Database\DriverInterface $driver Object from which database preferences and configuration will be extracted
* @return ?Money Given value casted from a database to a PHP equivalent.
* @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted
* @return ?\CakeDC\Money\Money Given value casted from a database to a PHP equivalent.
*/
public function toPHP(mixed $value, Driver $driver) : ?Money
public function toPHP(mixed $value, Driver $driver): ?Money
{
if ($value === null) {
return null;
Expand All @@ -51,32 +53,31 @@ public function toPHP(mixed $value, Driver $driver) : ?Money
* that make sense for the rest of the ORM/Database layers.
*
* @param mixed $value The value to convert.
* @return ?Money Converted value.
* @return ?\CakeDC\Money\Money Converted value.
*/
public function marshal($value) : ?Money
public function marshal(mixed $value): ?Money
{
if ($value === null) {
return null;
}
$currency = Configure::read('Money.currency', 'USD');

return MoneyUtil::money($value);
}

/**
* Casts given value from a PHP type to one acceptable by a database.
*
* @param ?Money $value Value to be converted to a database equivalent.
* @param \Cake\Database\DriverInterface $driver Object from which database preferences and configuration will be extracted.
* @param ?\CakeDC\Money\Money $value Value to be converted to a database equivalent.
* @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted.
* @return ?string Given PHP type casted to one acceptable by a database.
*/
public function toDatabase($value, Driver $driver) : ?string
public function toDatabase(mixed $value, Driver $driver): ?string
{
if ($value === null) {
return null;
}
if (!($value instanceof Money)) {
throw new \InvalidArgumentException(__('Value must be instance of Money'));
throw new InvalidArgumentException(__('Value must be instance of Money'));
}

return $value->getAmount();
Expand All @@ -86,16 +87,15 @@ public function toDatabase($value, Driver $driver) : ?string
* Casts given value to its Statement equivalent.
*
* @param mixed $value Value to be converted to PDO statement.
* @param \Cake\Database\DriverInterface $driver Object from which database preferences and configuration will be extracted.
* @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted.
* @return int Given value casted to its Statement equivalent.
*/
public function toStatement($value, Driver $driver) : int
public function toStatement(mixed $value, Driver $driver): int
{
if ($value === null) {
return PDO::PARAM_NULL;
}

return PDO::PARAM_INT;
}

}
Loading
Loading