Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Item | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCost | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Algorithm\Knapsack |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Algorithm\Knapsack; |
| 16 | |
| 17 | /** |
| 18 | * Item in the Knapsack |
| 19 | * |
| 20 | * @package phpOMS\Algorithm\Knapsack |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | class Item implements ItemInterface |
| 26 | { |
| 27 | /** |
| 28 | * Value of the item |
| 29 | * |
| 30 | * @var float |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | private float $value = 0.0; |
| 34 | |
| 35 | /** |
| 36 | * Cost of the item |
| 37 | * |
| 38 | * @var float |
| 39 | * @since 1.0.0 |
| 40 | */ |
| 41 | private float $cost = 0.0; |
| 42 | |
| 43 | /** |
| 44 | * Name of the item |
| 45 | * |
| 46 | * @var string |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | public string $name = ''; |
| 50 | |
| 51 | /** |
| 52 | * Cosntructor. |
| 53 | * |
| 54 | * @param float $value Value of the item |
| 55 | * @param float $cost Cost of the item |
| 56 | * |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public function __construct(float $value, float $cost, string $name = '') |
| 60 | { |
| 61 | $this->value = $value; |
| 62 | $this->cost = $cost; |
| 63 | $this->name = $name; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * {@inheritdoc} |
| 68 | */ |
| 69 | public function getValue() : float |
| 70 | { |
| 71 | return $this->value; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * {@inheritdoc} |
| 76 | */ |
| 77 | public function getCost() : float |
| 78 | { |
| 79 | return $this->cost; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * {@inheritdoc} |
| 84 | */ |
| 85 | public function getName() : string |
| 86 | { |
| 87 | return $this->name; |
| 88 | } |
| 89 | } |