| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of sebastian/lines-of-code.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
namespace SebastianBergmann\LinesOfCode;
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* @psalm-immutable
|
|
|
14 |
*/
|
|
|
15 |
final class LinesOfCode
|
|
|
16 |
{
|
|
|
17 |
/**
|
|
|
18 |
* @var int
|
|
|
19 |
*/
|
|
|
20 |
private $linesOfCode;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* @var int
|
|
|
24 |
*/
|
|
|
25 |
private $commentLinesOfCode;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* @var int
|
|
|
29 |
*/
|
|
|
30 |
private $nonCommentLinesOfCode;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* @var int
|
|
|
34 |
*/
|
|
|
35 |
private $logicalLinesOfCode;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* @throws IllogicalValuesException
|
|
|
39 |
* @throws NegativeValueException
|
|
|
40 |
*/
|
|
|
41 |
public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode)
|
|
|
42 |
{
|
|
|
43 |
if ($linesOfCode < 0) {
|
|
|
44 |
throw new NegativeValueException('$linesOfCode must not be negative');
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
if ($commentLinesOfCode < 0) {
|
|
|
48 |
throw new NegativeValueException('$commentLinesOfCode must not be negative');
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
if ($nonCommentLinesOfCode < 0) {
|
|
|
52 |
throw new NegativeValueException('$nonCommentLinesOfCode must not be negative');
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
if ($logicalLinesOfCode < 0) {
|
|
|
56 |
throw new NegativeValueException('$logicalLinesOfCode must not be negative');
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if ($linesOfCode - $commentLinesOfCode !== $nonCommentLinesOfCode) {
|
|
|
60 |
throw new IllogicalValuesException('$linesOfCode !== $commentLinesOfCode + $nonCommentLinesOfCode');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
$this->linesOfCode = $linesOfCode;
|
|
|
64 |
$this->commentLinesOfCode = $commentLinesOfCode;
|
|
|
65 |
$this->nonCommentLinesOfCode = $nonCommentLinesOfCode;
|
|
|
66 |
$this->logicalLinesOfCode = $logicalLinesOfCode;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public function linesOfCode(): int
|
|
|
70 |
{
|
|
|
71 |
return $this->linesOfCode;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
public function commentLinesOfCode(): int
|
|
|
75 |
{
|
|
|
76 |
return $this->commentLinesOfCode;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
public function nonCommentLinesOfCode(): int
|
|
|
80 |
{
|
|
|
81 |
return $this->nonCommentLinesOfCode;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public function logicalLinesOfCode(): int
|
|
|
85 |
{
|
|
|
86 |
return $this->logicalLinesOfCode;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
public function plus(self $other): self
|
|
|
90 |
{
|
|
|
91 |
return new self(
|
|
|
92 |
$this->linesOfCode() + $other->linesOfCode(),
|
|
|
93 |
$this->commentLinesOfCode() + $other->commentLinesOfCode(),
|
|
|
94 |
$this->nonCommentLinesOfCode() + $other->nonCommentLinesOfCode(),
|
|
|
95 |
$this->logicalLinesOfCode() + $other->logicalLinesOfCode(),
|
|
|
96 |
);
|
|
|
97 |
}
|
|
|
98 |
}
|