Skip to content

Commit 5d48d45

Browse files
committed
remake
1 parent 83cdef4 commit 5d48d45

16 files changed

+1221
-1111
lines changed

src/Aggregate/AbstractAggregator.php

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
/**
1616
* The aggregator
17-
* @template G of \ArrayIterator\Profiler\Interfaces\GroupInterface<string, array<integer, RecordInterface>>
18-
* @template-implements AggregatorInterface<G>
1917
*/
2018
class AbstractAggregator implements
2119
SeverityInterface,
@@ -37,12 +35,12 @@ class AbstractAggregator implements
3735
protected string $groupName = '';
3836

3937
/**
40-
* @var array<string, AggregationInterface<G>> $aggregations
38+
* @var array<string, AggregationInterface> $aggregations
4139
*/
4240
protected array $aggregations = [];
4341

4442
/**
45-
* @var AggregationInterface<G> $internalAggregation the internal aggregation
43+
* @var AggregationInterface $internalAggregation the internal aggregation
4644
*/
4745
protected AggregationInterface $internalAggregation;
4846

@@ -66,32 +64,12 @@ class AbstractAggregator implements
6664
*/
6765
protected int $criticalExecutionCount = DurationInterface::TIMESPAN_CRITICAL;
6866

69-
/**
70-
* @inheritDoc
71-
*/
72-
final public function __construct()
73-
{
74-
$this->name ??= get_class($this);
75-
$this->onConstruct();
76-
}
77-
78-
/**
79-
* Call when constructed
80-
*
81-
* @abstract
82-
* @phpstan-return mixed
83-
*/
84-
protected function onConstruct()
85-
{
86-
// override
87-
}
88-
8967
/**
9068
* @inheritDoc
9169
*/
9270
public function getName() : string
9371
{
94-
return $this->name;
72+
return $this->name ??= get_class($this);
9573
}
9674

9775
/**
@@ -134,6 +112,7 @@ public function aggregate(RecordInterface $record) : bool
134112
/**
135113
* Get record identity (record name)
136114
*
115+
* @param RecordInterface $record
137116
* @return string the record name
138117
*/
139118
public function getIdentity(RecordInterface $record) : string
@@ -162,14 +141,7 @@ public function getAggregations() : array
162141
*/
163142
public function getAggregation(string $identity) : AggregationInterface
164143
{
165-
if (isset($this->aggregations[$identity])) {
166-
return $this->aggregations[$identity];
167-
}
168-
$aggregation = new Aggregation($identity);
169-
/**
170-
* @var AggregationInterface<G> $aggregation
171-
*/
172-
return $this->aggregations[$identity] = $aggregation;
144+
return $this->aggregations[$identity] ??= new Aggregation($identity);
173145
}
174146

175147
/**
@@ -182,7 +154,7 @@ public function getInternalAggregation() : AggregationInterface
182154
}
183155
$aggregation = new InternalAggregation();
184156
/**
185-
* @var AggregationInterface<G> $aggregation
157+
* @var AggregationInterface $aggregation
186158
*/
187159
return $this->internalAggregation ??= $aggregation;
188160
}
@@ -306,28 +278,28 @@ public function getSeverity() : int
306278
{
307279
$severity = $this->getFactorySeverity();
308280
$total = $this->getTotalExecution();
309-
if ($this->isCritical()) {
310-
return $severity;
281+
if (($severity & self::CRITICAL) === self::CRITICAL) {
282+
return self::CRITICAL;
311283
}
312284
if ($total >= $this->getCriticalExecutionCount()) {
313285
$severity |= self::CRITICAL;
314286
return $severity;
315287
}
316-
if ($this->isWarning()) {
288+
if (($severity & self::WARNING) === self::WARNING) {
317289
return $severity;
318290
}
319291
if ($total >= $this->getWarningExecutionCount()) {
320292
$severity |= self::WARNING;
321293
return $severity;
322294
}
323-
if ($this->isNotice()) {
295+
if (($severity & self::NOTICE) === self::NOTICE) {
324296
return $severity;
325297
}
326298
if ($total >= $this->getNoticeExecutionCount()) {
327299
$severity |= self::NOTICE;
328300
return $severity;
329301
}
330-
if ($this->isInfo()) {
302+
if (($severity & self::INFO) === self::INFO) {
331303
return $severity;
332304
}
333305
if ($total >= $this->getInfoExecutionCount()) {
@@ -367,7 +339,7 @@ public function count() : int
367339
* maximum: float,
368340
* average: float,
369341
* },
370-
* "aggregations": array<string, AggregationInterface<G>>
342+
* "aggregations": array<string, AggregationInterface>
371343
* }
372344
*/
373345
public function toArray() : array
@@ -403,7 +375,7 @@ public function toArray() : array
403375
* maximum: float,
404376
* average: float,
405377
* },
406-
* "aggregations": array<string, AggregationInterface<G>>
378+
* "aggregations": array<string, AggregationInterface>
407379
* }
408380
*/
409381
public function jsonSerialize() : array

src/Aggregate/Aggregation.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
/**
1313
* Aggregation object
14-
*
15-
* @template G of \ArrayIterator\Profiler\Interfaces\GroupInterface<string, array<integer, RecordInterface>>
16-
* @template-implements AggregationInterface<G>
1714
*/
1815
class Aggregation implements AggregationInterface
1916
{
@@ -25,7 +22,7 @@ class Aggregation implements AggregationInterface
2522
/**
2623
* Get records
2724
*
28-
* @var array<integer, RecordInterface>
25+
* @var array<int, RecordInterface>
2926
* Index key as
3027
* @uses spl_object_id(RecordInterface)
3128
*/
@@ -106,7 +103,7 @@ final public function aggregate(RecordInterface $record, AggregatorInterface $ag
106103
/**
107104
* Call when aggregated
108105
* @param RecordInterface $record
109-
* @param AggregatorInterface<G> $aggregator
106+
* @param AggregatorInterface $aggregator
110107
* @abtract
111108
* @phpstan-return mixed|void
112109
*/

src/Aggregate/Interfaces/AggregationInterface.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/**
1010
* Aggregation object
11-
* @template G of \ArrayIterator\Profiler\Interfaces\GroupInterface<string, array<integer, RecordInterface>>
1211
*/
1312
interface AggregationInterface extends JsonSerializable
1413
{
@@ -21,7 +20,7 @@ public function getName() : string;
2120
* Aggregate the record
2221
*
2322
* @param RecordInterface $record
24-
* @param AggregatorInterface<G> $aggregator
23+
* @param AggregatorInterface $aggregator
2524
*
2625
* @return static
2726
*/
@@ -78,7 +77,7 @@ public function getMaximumDuration() : float;
7877
public function getAverageDuration() : float;
7978

8079
/**
81-
* @return array<integer, RecordInterface>
80+
* @return array<int, RecordInterface>
8281
*/
8382
public function getRecords() : array;
8483

src/Aggregate/Interfaces/AggregatorInterface.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@
99

1010
/**
1111
* The aggregator
12-
* @template TValue of \ArrayIterator\Profiler\Interfaces\GroupInterface<array<integer, RecordInterface>>
1312
*/
1413
interface AggregatorInterface extends SeverityInterface, AggregateInterface, JsonSerializable
1514
{
16-
/**
17-
* Aggregator constructor, No parameter or optional
18-
*/
19-
public function __construct();
20-
2115
/**
2216
* Get aggregator name
2317
*
@@ -47,7 +41,7 @@ public function accepted(RecordInterface $record) : bool;
4741
public function aggregate(RecordInterface $record) : bool;
4842

4943
/**
50-
* @return array<string, AggregationInterface<TValue>>
44+
* @return array<string, AggregationInterface>
5145
*/
5246
public function getAggregations() : array;
5347

@@ -56,14 +50,14 @@ public function getAggregations() : array;
5650
*
5751
* @param string $identity
5852
*
59-
* @return AggregationInterface<TValue>
53+
* @return AggregationInterface
6054
*/
6155
public function getAggregation(string $identity) : AggregationInterface;
6256

6357
/**
6458
* Get the internal aggregation
6559
*
66-
* @return AggregationInterface<TValue>
60+
* @return AggregationInterface
6761
*/
6862
public function getInternalAggregation() : AggregationInterface;
6963

@@ -124,10 +118,11 @@ public function getRecords() : array;
124118
* maximum: float,
125119
* average: float,
126120
* },
127-
* "aggregations": array<string, AggregationInterface<TValue>>
121+
* "aggregations": array<string, AggregationInterface>
128122
* }
129123
*/
130124
public function toArray() : array;
125+
131126
/**
132127
* Get array definitions
133128
*
@@ -143,7 +138,7 @@ public function toArray() : array;
143138
* maximum: float,
144139
* average: float,
145140
* },
146-
* "aggregations": array<string, AggregationInterface<TValue>>
141+
* "aggregations": array<string, AggregationInterface>
147142
* }
148143
*/
149144
public function jsonSerialize() : array;

src/Aggregate/InternalAggregation.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
/**
77
* The internal Aggregation
8-
* @template TRecord of \ArrayIterator\Profiler\Interfaces\RecordInterface
9-
* @template G of \ArrayIterator\Profiler\Interfaces\GroupInterface<string, array<integer, TRecord>>
10-
* @template-extends Aggregation<G>
118
*/
129
class InternalAggregation extends Aggregation
1310
{

src/Aggregate/ProfilerAggregator.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ArrayIterator\Profiler\Aggregate;
5+
6+
use ArrayIterator\Profiler\Interfaces\ProfilerInterface;
7+
use ArrayIterator\Profiler\Interfaces\RecordInterface;
8+
9+
/**
10+
* The aggregator
11+
*/
12+
class ProfilerAggregator extends AbstractAggregator
13+
{
14+
/**
15+
* @var ProfilerInterface $profiler
16+
*/
17+
protected ProfilerInterface $profiler;
18+
19+
/**
20+
* @param ProfilerInterface $profiler
21+
*/
22+
public function __construct(ProfilerInterface $profiler)
23+
{
24+
$this->profiler = $profiler;
25+
}
26+
27+
/**
28+
* Get profiler
29+
*
30+
* @return ProfilerInterface $profiler
31+
*/
32+
public function getProfiler(): ProfilerInterface
33+
{
34+
return $this->profiler;
35+
}
36+
37+
/**
38+
* @param ProfilerInterface $profiler
39+
* @return bool
40+
*/
41+
protected function isEqualProfiler(ProfilerInterface $profiler) : bool
42+
{
43+
return $profiler === $this->getProfiler();
44+
}
45+
46+
/**
47+
* @inheritDoc
48+
*/
49+
public function accepted(RecordInterface $record): bool
50+
{
51+
if ($record->isStopped()) {
52+
return false;
53+
}
54+
return $this->isEqualProfiler($record->getGroup()->getProfiler());
55+
}
56+
}

src/Group.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
/**
1919
* Object group to store / grouping record
20-
*
2120
* @uses RecordInterface
2221
*/
2322
class Group implements GroupInterface, ClearableInterface
@@ -43,14 +42,14 @@ class Group implements GroupInterface, ClearableInterface
4342
private array $stoppedQueue = [];
4443

4544
/**
46-
* @var ProfilerInterface<string, $this> $profiler the profiler
45+
* @var ProfilerInterface $profiler the profiler
4746
*/
4847
private ProfilerInterface $profiler;
4948

5049
/**
5150
* Group constructor
5251
*
53-
* @param ProfilerInterface<string, $this> $profiler
52+
* @param ProfilerInterface $profiler
5453
* @param string $name
5554
* @internal
5655
*/

src/Interfaces/GroupInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Object group to store / grouping record
1313
*
1414
* @uses RecordInterface
15-
* @template-extends IteratorAggregate<string, array<integer, RecordInterface>>
15+
* @template-extends IteratorAggregate<string, array<int, RecordInterface>>
1616
*/
1717
interface GroupInterface extends
1818
SortableRecordInterface,
@@ -25,7 +25,7 @@ interface GroupInterface extends
2525
{
2626
/**
2727
* Get the profiler
28-
* @return ProfilerInterface<string, $this> the profiler
28+
* @return ProfilerInterface the profiler
2929
*/
3030
public function getProfiler(): ProfilerInterface;
3131

@@ -48,7 +48,7 @@ public function has(string $recordName): bool;
4848
/**
4949
* Merge the group
5050
*
51-
* @param GroupInterface<array<integer, RecordInterface>> $group the group
51+
* @param GroupInterface $group the group
5252
* @phpstan-return mixed
5353
*/
5454
public function merge(GroupInterface $group);

0 commit comments

Comments
 (0)