Skip to content

Commit

Permalink
Update namespace for interfaces and refactor constants
Browse files Browse the repository at this point in the history
Moved interface files to Contracts directory for better organization. Refactored magic numbers in codes to use constants from new FiguresInterface for improved readability. Test cases and documentation were updated accordingly.

Signed-off-by: Marcel Strahl <[email protected]>
  • Loading branch information
Dropelikeit committed May 20, 2024
1 parent 9d56410 commit f234ba4
Show file tree
Hide file tree
Showing 46 changed files with 202 additions and 87 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -20,7 +20,7 @@ jobs:
php-version: "8.1"

- name: "Cache composer packages"
uses: "actions/cache@v3"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-composer-locked-${{ hashFiles('composer.lock') }}"
Expand All @@ -43,7 +43,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -53,7 +53,7 @@ jobs:
php-version: "8.2"

- name: "Cache composer packages"
uses: "actions/cache@v3"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-composer-locked-${{ hashFiles('composer.lock') }}"
Expand All @@ -76,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -86,7 +86,7 @@ jobs:
php-version: "8.3"

- name: "Cache composer packages"
uses: "actions/cache@v3"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-composer-locked-${{ hashFiles('composer.lock') }}"
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ This Changelog refers to all changes since v5.0.0

# v5.x.x
+ Upgrade of dependencies, removal of PHPStan as I focused more on Psalm.
+ All test classes are now final and use attributes instead of annotations.
+ All test classes are now final and use attributes instead of annotations.
+ Using InfectionPHP to check the effectiveness of the test set.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Marcel Strahl
Copyright (c) 2018-2024 Marcel Strahl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.51",
"infection/infection": "^0.27.10",
"phpstan/extension-installer": "*",
"phpunit/phpunit": "^10.5 | ^11.0",
"psalm/plugin-phpunit": "^0.18",
"squizlabs/php_codesniffer": "^3.9",
Expand All @@ -29,7 +31,10 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
}
},
"prefer-stable": true,
"scripts": {
Expand All @@ -38,6 +43,7 @@
"cs-fix": "php-cs-fixer --using-cache=no fix",
"test": "export XDEBUG_MODE=coverage && vendor/bin/phpunit --configuration phpunit.xml",
"psalm": "vendor/bin/psalm --no-cache",
"infection": "infection --threads=4",
"check": [
"@phpcs",
"@cs-check",
Expand Down
6 changes: 1 addition & 5 deletions docs/price-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ In order to enter a value from a price object into the price formatter, the Cent
```php
<?php

use MarcelStrahl\PriceCalculator\Helpers\View\PriceFormatter;
use MarcelStrahl\PriceCalculator\Facade\UnitConverter;
use MarcelStrahl\PriceCalculator\Factory\ConverterFactoryInterface;
use MarcelStrahl\PriceCalculator\Helpers\Entity\Price;
use function var_dump;
use MarcelStrahl\PriceCalculator\Contracts\Factory\ConverterFactoryInterface;use MarcelStrahl\PriceCalculator\Facade\UnitConverter;use MarcelStrahl\PriceCalculator\Helpers\Entity\Price;use MarcelStrahl\PriceCalculator\Helpers\View\PriceFormatter;

$calculatedResultInCent = Price::create(1010);

Expand Down
9 changes: 4 additions & 5 deletions docs/unit-converter.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ The unit converter has a method:
This class has a facade for easy use of the unit converter.

Use with facade:

```php
use MarcelStrahl\PriceCalculator\Factory\ConverterFactoryInterface;
use MarcelStrahl\PriceCalculator\Facade\UnitConverter;
use MarcelStrahl\PriceCalculator\Contracts\Factory\ConverterFactoryInterface;use MarcelStrahl\PriceCalculator\Facade\UnitConverter;

$converter = UnitConverter::getConverter();

Expand All @@ -28,10 +28,9 @@ $euroToCentConverter = $converter->convert(ConverterFactoryInterface::EURO_TO_CE
```

Use without facade:

```php
use MarcelStrahl\PriceCalculator\Factory\ConverterFactoryInterface;
use MarcelStrahl\PriceCalculator\UnitConverter;
use MarcelStrahl\PriceCalculator\Factory\Converter;
use MarcelStrahl\PriceCalculator\Contracts\Factory\ConverterFactoryInterface;use MarcelStrahl\PriceCalculator\Factory\Converter;use MarcelStrahl\PriceCalculator\UnitConverter;

$converter = new UnitConverter(new Converter());

Expand Down
33 changes: 33 additions & 0 deletions infection.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"src"
],
"excludes": [
"src/Helpers/Mathematics.php"
]
},
"mutators": {
"@default": true,
"BCMath": {
"settings": {
"bcdiv": false,
"bcmul": false,
"bcadd": false,
"bcsub": false
}
},
},
"logs": {
"html": "infection.html",
"summary": "summary.log",
"json": "infection-log.json",
"perMutator": "per-mutator.md",
"github": true,
"stryker": {
"badge": "master"
},
"summaryJson": "summary.json"
},
}
2 changes: 2 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
<file>./src/Contracts/MathematicsInterface.php</file>
<file>./src/Helpers/Mathematics.php</file>
</exclude>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
<file name="src/Helpers/Mathematics.php"/>
<file name="src/Contracts/MathematicsInterface.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Price calculator

[![Build Status](https://travis-ci.org/Dropelikeit/PriceCalculator.svg?branch=master)](https://travis-ci.org/Dropelikeit/PriceCalculator)
![Workflow status](https://github.com/Dropelikeit/PriceCalculator/actions/workflows/ci.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/Dropelikeit/PriceCalculator/badge.svg?branch=master)](https://coveralls.io/github/Dropelikeit/PriceCalculator?branch=master)
[![Monthly Downloads](https://poser.pugx.org/marcel-strahl/price-calculator/d/monthly)](https://packagist.org/packages/marcel-strahl/price-calculator)
[![Daily Downloads](https://poser.pugx.org/marcel-strahl/price-calculator/d/daily)](https://packagist.org/packages/marcel-strahl/price-calculator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Helpers\Converter;
namespace MarcelStrahl\PriceCalculator\Contracts\Converter;

/**
* @author Marcel Strahl <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Factory;
namespace MarcelStrahl\PriceCalculator\Contracts\Factory;

use MarcelStrahl\PriceCalculator\Contracts\Converter\ConverterInterface;
use MarcelStrahl\PriceCalculator\Exceptions\PriceCalculatorFactoryException;
use MarcelStrahl\PriceCalculator\Helpers\Converter\ConverterInterface;

/**
* @author Marcel Strahl <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator;
namespace MarcelStrahl\PriceCalculator\Contracts;

use MarcelStrahl\PriceCalculator\Helpers\Entity\Price;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Service;
namespace MarcelStrahl\PriceCalculator\Contracts\Service;

use MarcelStrahl\PriceCalculator\Helpers\Entity\Discount;
use MarcelStrahl\PriceCalculator\Helpers\Entity\Price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Service;
namespace MarcelStrahl\PriceCalculator\Contracts\Service;

use MarcelStrahl\PriceCalculator\Helpers\Entity\Price;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Helpers\Types;
namespace MarcelStrahl\PriceCalculator\Contracts\Type;

/**
* Interface Discount
Expand Down
16 changes: 16 additions & 0 deletions src/Contracts/Type/FiguresInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Contracts\Type;

interface FiguresInterface
{
public const INTEGER_ZERO = 0;
public const INTEGER_ONE = 1;
public const INTEGER_TWO = 2;
public const INTEGER_HUNDRED = 100;

public const FLOAT_ZERO = .0;

public const STRING_HUNDRED = '100';
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Helpers\Types;
namespace MarcelStrahl\PriceCalculator\Contracts\Type;

/**
* @author Marcel Strahl <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator;
namespace MarcelStrahl\PriceCalculator\Contracts;

use MarcelStrahl\PriceCalculator\Helpers\Converter\ConverterInterface;
use MarcelStrahl\PriceCalculator\Contracts\Converter\ConverterInterface;

/**
* @author Marcel Strahl <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

declare(strict_types=1);

namespace MarcelStrahl\PriceCalculator\Helpers\View;
namespace MarcelStrahl\PriceCalculator\Contracts\View;

/**
* Interface Formatter
* @author Marcel Strahl <[email protected]>
* @package Src\Helpers\View
*/
interface Formatter
{
Expand Down
2 changes: 1 addition & 1 deletion src/Facade/PriceCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace MarcelStrahl\PriceCalculator\Facade;

use MarcelStrahl\PriceCalculator\Contracts\PriceCalculatorInterface;
use MarcelStrahl\PriceCalculator\PriceCalculator as PriceCalculatorService;
use MarcelStrahl\PriceCalculator\PriceCalculatorInterface;

/**
* @author Marcel Strahl <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/Facade/VatCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace MarcelStrahl\PriceCalculator\Facade;

use MarcelStrahl\PriceCalculator\Contracts\PriceCalculatorInterface;
use MarcelStrahl\PriceCalculator\Helpers\Entity\Vat;
use MarcelStrahl\PriceCalculator\PriceCalculatorInterface;
use MarcelStrahl\PriceCalculator\Service\VatCalculator as VatCalculatorService;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Factory/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace MarcelStrahl\PriceCalculator\Factory;

use MarcelStrahl\PriceCalculator\Contracts\Converter\ConverterInterface;
use MarcelStrahl\PriceCalculator\Contracts\Factory\ConverterFactoryInterface;
use MarcelStrahl\PriceCalculator\Exceptions\PriceCalculatorFactoryException;
use MarcelStrahl\PriceCalculator\Helpers\Converter\ConverterInterface;
use MarcelStrahl\PriceCalculator\Helpers\Converter\Currencies\CentToEuro;
use MarcelStrahl\PriceCalculator\Helpers\Converter\Currencies\EuroToCent;

Expand Down
9 changes: 5 additions & 4 deletions src/Helpers/Converter/Currencies/CentToEuro.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace MarcelStrahl\PriceCalculator\Helpers\Converter\Currencies;

use MarcelStrahl\PriceCalculator\Helpers\Converter\ConverterInterface;
use MarcelStrahl\PriceCalculator\Contracts\Converter\ConverterInterface;
use MarcelStrahl\PriceCalculator\Contracts\Type\FiguresInterface;

/**
* @author Marcel Strahl <[email protected]>
Expand All @@ -17,17 +18,17 @@ class CentToEuro implements ConverterInterface
public function convert(float $amount): float
{
if ($this->isEmpty($amount)) {
return .0;
return FiguresInterface::FLOAT_ZERO;
}

return (float) bcdiv((string) $amount, '100', 2);
return (float) bcdiv((string) $amount, FiguresInterface::STRING_HUNDRED, FiguresInterface::INTEGER_TWO);
}

/**
* {@inheritdoc}
*/
public function isEmpty(float $amount): bool
{
return empty($amount) || $amount < 0;
return empty($amount);
}
}
Loading

0 comments on commit f234ba4

Please sign in to comment.