Issues (4)

src/ValueObject/MoneyInterface.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/money-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Money\ValueObject;
10
11
use Daikon\Interop\MakeEmptyInterface;
12
use Daikon\ValueObject\ValueObjectInterface;
13
use Money\Money;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Daikon\Money\ValueObject\Money. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
15
interface MoneyInterface extends MakeEmptyInterface, ValueObjectInterface
16
{
17
    public const ROUND_UP = Money::ROUND_UP;
18
    public const ROUND_DOWN = Money::ROUND_DOWN;
19
    public const ROUND_HALF_UP = Money::ROUND_HALF_UP;
20
    public const ROUND_HALF_DOWN = Money::ROUND_HALF_DOWN;
21
22
    /** @param null|string $currency */
23
    public static function zero($currency = null): self;
24
25
    public function getAmount(): string;
26
27
    public function getCurrency(): string;
28
29
    public function add(MoneyInterface $money): self;
30
31
    public function subtract(MoneyInterface $money): self;
32
33
    /** @param float|int|string $multiplier */
34
    public function multiply($multiplier, int $roundingMode = self::ROUND_HALF_UP): self;
35
36
    /** @param float|int|string $divisor */
37
    public function divide($divisor, int $roundingMode = self::ROUND_HALF_UP): self;
38
39
    /** @param float|int|string $percentage */
40
    public function percentage($percentage): self;
41
42
    public function isZero(): bool;
43
44
    public function isPositive(): bool;
45
46
    public function isNegative(): bool;
47
48
    public function isLessThanOrEqual(MoneyInterface $money): bool;
49
50
    public function isGreaterThanOrEqual(MoneyInterface $money): bool;
51
}
52