Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alecrabbit committed Dec 4, 2023
2 parents baf459a + d05a860 commit 0af02cf
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 119 deletions.
4 changes: 2 additions & 2 deletions .tools/.report/.build/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Code Coverage Report Summary:
Classes: 100.00% (207/207)
Methods: 100.00% (737/737)
Lines: 100.00% (3718/3718)
Methods: 100.00% (736/736)
Lines: 100.00% (3715/3715)

2 changes: 1 addition & 1 deletion .tools/.report/.deptrac/.deptrac.report
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Violations 0
Skipped violations 0
Uncovered 177
Allowed 2543
Allowed 2545
Warnings 0
Errors 0
-------------------- ------
Expand Down
30 changes: 15 additions & 15 deletions .tools/.report/.phploc/.src.phploc.report
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Directories 77
Files 419

Size
Lines of Code (LOC) 13578
Comment Lines of Code (CLOC) 739 (5.44%)
Non-Comment Lines of Code (NCLOC) 12839 (94.56%)
Logical Lines of Code (LLOC) 1419 (10.45%)
Classes 1318 (92.88%)
Lines of Code (LOC) 13573
Comment Lines of Code (CLOC) 737 (5.43%)
Non-Comment Lines of Code (NCLOC) 12836 (94.57%)
Logical Lines of Code (LLOC) 1418 (10.45%)
Classes 1317 (92.88%)
Average Class Length 3
Minimum Class Length 0
Maximum Class Length 27
Expand Down Expand Up @@ -36,12 +36,12 @@ Dependencies
Global Constants 0 (0.00%)
Global Variables 0 (0.00%)
Super-Global Variables 0 (0.00%)
Attribute Accesses 604
Non-Static 588 (97.35%)
Attribute Accesses 603
Non-Static 587 (97.35%)
Static 16 (2.65%)
Method Calls 758
Non-Static 681 (89.84%)
Static 77 (10.16%)
Method Calls 755
Non-Static 678 (89.80%)
Static 77 (10.20%)

Structure
Namespaces 77
Expand All @@ -52,14 +52,14 @@ Structure
Concrete Classes 191 (93.17%)
Final Classes 70 (36.65%)
Non-Final Classes 121 (63.35%)
Methods 968
Methods 969
Scope
Non-Static Methods 903 (93.29%)
Non-Static Methods 904 (93.29%)
Static Methods 65 (6.71%)
Visibility
Public Methods 763 (78.82%)
Protected Methods 64 (6.61%)
Private Methods 141 (14.57%)
Public Methods 764 (78.84%)
Protected Methods 64 (6.60%)
Private Methods 141 (14.55%)
Functions 37
Named Functions 7 (18.92%)
Anonymous Functions 30 (81.08%)
Expand Down
26 changes: 13 additions & 13 deletions .tools/.report/.phploc/.test.phploc.report
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Directories 74
Files 273

Size
Lines of Code (LOC) 30544
Lines of Code (LOC) 30609
Comment Lines of Code (CLOC) 458 (1.50%)
Non-Comment Lines of Code (NCLOC) 30086 (98.50%)
Logical Lines of Code (LLOC) 6687 (21.89%)
Classes 6679 (99.88%)
Non-Comment Lines of Code (NCLOC) 30151 (98.50%)
Logical Lines of Code (LLOC) 6711 (21.92%)
Classes 6703 (99.88%)
Average Class Length 24
Minimum Class Length 0
Maximum Class Length 871
Expand All @@ -24,7 +24,7 @@ Size

Cyclomatic Complexity
Average Complexity per LLOC 0.07
Average Complexity per Class 2.60
Average Complexity per Class 2.59
Minimum Class Complexity 1.00
Maximum Class Complexity 16.00
Average Complexity per Method 1.26
Expand All @@ -39,9 +39,9 @@ Dependencies
Attribute Accesses 28
Non-Static 23 (82.14%)
Static 5 (17.86%)
Method Calls 9132
Non-Static 5989 (65.58%)
Static 3143 (34.42%)
Method Calls 9164
Non-Static 6009 (65.57%)
Static 3155 (34.43%)

Structure
Namespaces 74
Expand All @@ -52,14 +52,14 @@ Structure
Concrete Classes 266 (98.52%)
Final Classes 248 (93.23%)
Non-Final Classes 18 (6.77%)
Methods 1724
Methods 1726
Scope
Non-Static Methods 1616 (93.74%)
Non-Static Methods 1618 (93.74%)
Static Methods 108 (6.26%)
Visibility
Public Methods 1036 (60.09%)
Protected Methods 313 (18.16%)
Private Methods 375 (21.75%)
Public Methods 1038 (60.14%)
Protected Methods 313 (18.13%)
Private Methods 375 (21.73%)
Functions 90
Named Functions 2 (2.22%)
Anonymous Functions 88 (97.78%)
Expand Down
12 changes: 3 additions & 9 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $driver = \AlecRabbit\Spinner\Facade::getDriver();

while (true) {
$driver->render();
usleep(100000);
// do some work
}
```

Expand All @@ -49,13 +49,7 @@ class Dots extends ACharPalette {
protected function sequence(): Traversable
{
// note the width of each element
$a = [' ', '. ', '.. ', '...', ' ..', ' .', ' '];

if ($this->options->getReversed()) {
$a = array_reverse($a);
}

yield from $a;
yield from [' ', '. ', '.. ', '...', ' ..', ' .', ' '];
}
}
```
Expand All @@ -67,7 +61,7 @@ class Greeny extends AStylePalette {
protected function ansi4StyleFrames(): Traversable
{
yield from [
$this->createFrame("\e[92m%s\e[39m"),
$this->createFrame("\e[92m%s\e[39m"), // note the ANSI codes
];
}

Expand Down
5 changes: 1 addition & 4 deletions example/async/bootstrap.async.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ static function (IContainer $container): IDriverLinker {
},
IServiceDefinition::SINGLETON,
),
);

// Register driver linker with output factory
$registry->bind(
// Register driver linker decorator factory
new ServiceDefinition(IDriverLinkerDecoratorFactory::class, DriverLinkerDecoratorFactory::class),
);

Expand Down
34 changes: 15 additions & 19 deletions example/benchmark/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,28 @@

$registry = DefinitionRegistry::getInstance();

$registry->bind(new ServiceDefinition(ITimer::class, new MicrosecondTimer()));
$registry->bind(new ServiceDefinition(IDriverProviderFactory::class, BenchmarkingDriverProviderFactory::class));
$registry->bind(new ServiceDefinition(IResultMaker::class, ResultMaker::class));
$registry->bind(new ServiceDefinition(IBenchmarkResultsFactory::class, BenchmarkResultsFactory::class));
$registry->bind(new ServiceDefinition(IBenchmarkingDriverFactory::class, BenchmarkingDriverFactory::class));
$registry->bind(new ServiceDefinition(IBenchmarkingDriverBuilder::class, BenchmarkingDriverBuilder::class));
$registry->bind(new ServiceDefinition(IBenchmarkFactory::class, BenchmarkFactory::class));
$registry->bind(new ServiceDefinition(IMeasurementFactory::class, MeasurementFactory::class));
$registry->bind(new ServiceDefinition(IStopwatchBuilder::class, StopwatchBuilder::class));
$registry->bind(new ServiceDefinition(IStopwatchFactory::class, StopwatchFactory::class));
$registry->bind(new ServiceDefinition(IReportPrinterBuilder::class, ReportPrinterBuilder::class));
$registry->bind(new ServiceDefinition(IReportFormatter::class, ReportFormatter::class));
$registry->bind(new ServiceDefinition(IDatetimeFormatter::class, DatetimeFormatter::class));
$registry->bind(new ServiceDefinition(IResultFormatter::class, ResultFormatter::class));
$registry->bind(new ServiceDefinition(IKeyFormatter::class, KeyFormatter::class));

$registry->bind(
new ServiceDefinition(ITimer::class, new MicrosecondTimer()),
new ServiceDefinition(IDriverProviderFactory::class, BenchmarkingDriverProviderFactory::class),
new ServiceDefinition(IResultMaker::class, ResultMaker::class),
new ServiceDefinition(IBenchmarkResultsFactory::class, BenchmarkResultsFactory::class),
new ServiceDefinition(IBenchmarkingDriverFactory::class, BenchmarkingDriverFactory::class),
new ServiceDefinition(IBenchmarkingDriverBuilder::class, BenchmarkingDriverBuilder::class),
new ServiceDefinition(IBenchmarkFactory::class, BenchmarkFactory::class),
new ServiceDefinition(IMeasurementFactory::class, MeasurementFactory::class),
new ServiceDefinition(IStopwatchBuilder::class, StopwatchBuilder::class),
new ServiceDefinition(IStopwatchFactory::class, StopwatchFactory::class),
new ServiceDefinition(IReportPrinterBuilder::class, ReportPrinterBuilder::class),
new ServiceDefinition(IReportFormatter::class, ReportFormatter::class),
new ServiceDefinition(IDatetimeFormatter::class, DatetimeFormatter::class),
new ServiceDefinition(IResultFormatter::class, ResultFormatter::class),
new ServiceDefinition(IKeyFormatter::class, KeyFormatter::class),
new ServiceDefinition(
IReportPrinter::class,
static function (ContainerInterface $container): IReportPrinter {
return $container->get(IReportPrinterFactory::class)->create();
}
),
);

$registry->bind(
new ServiceDefinition(
IReportPrinterFactory::class,
static function (ContainerInterface $container): IReportPrinterFactory {
Expand Down
3 changes: 0 additions & 3 deletions example/benchmark/container.sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public function write(Traversable $data): void
}
}
),
);

$registry->bind(
new ServiceDefinition(
IDeltaTimer::class,
new class() implements IDeltaTimer {
Expand Down
2 changes: 1 addition & 1 deletion src/Spinner/Container/Contract/IDefinitionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface IDefinitionRegistry
*/
public function load(): Traversable;

public function bind(IServiceDefinition $serviceDefinition): void;
public function bind(IServiceDefinition ...$serviceDefinitions): void;
}
6 changes: 4 additions & 2 deletions src/Spinner/Container/DefinitionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public function load(): Traversable
yield from $this->definitions;
}

public function bind(IServiceDefinition $serviceDefinition): void
public function bind(IServiceDefinition ...$serviceDefinitions): void
{
$this->definitions->offsetSet($serviceDefinition->getId(), $serviceDefinition);
foreach ($serviceDefinitions as $serviceDefinition) {
$this->definitions->offsetSet($serviceDefinition->getId(), $serviceDefinition);
}
}
}
21 changes: 7 additions & 14 deletions src/Spinner/Core/Palette/A/ACharPalette.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,18 @@ abstract class ACharPalette extends APalette implements ICharPalette
*/
protected function getEntries(?IPaletteMode $mode = null): Traversable
{
/** @var string $element */
foreach ($this->getSequence() as $element) {
/** @var string|ICharFrame $element */
foreach ($this->sequence() as $element) {
if ($element instanceof ICharFrame) {
yield $element;
continue;
}
yield $this->createFrame($element);
}
}

protected function getSequence(): Traversable
{
$sequence = $this->sequence();

if ($this->options->getReversed()) {
$sequence = array_reverse(iterator_to_array($sequence));
}

yield from $sequence;
}

/**
* @return Traversable<string>
* @return Traversable<string|ICharFrame>
*/
abstract protected function sequence(): Traversable;

Expand Down
1 change: 1 addition & 0 deletions src/Spinner/Core/Palette/A/APalette.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(
) {
}

// FIXME (2023-12-04 16:9) [Alec Rabbit]: extract functionality to PaletteTemplateFactory->create($palette)
public function getTemplate(?IPaletteMode $mode = null): IPaletteTemplate
{
return new PaletteTemplate(
Expand Down
4 changes: 3 additions & 1 deletion src/Spinner/Core/Palette/A/AStylePalette.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ abstract class AStylePalette extends APalette implements IStylePalette
{
protected function getOptions(?IPaletteMode $mode = null): IPaletteOptions
{
$interval = $this->options->getInterval() ?? $this->getInterval($this->extractStylingMode($mode));

$this->options =
new PaletteOptions(
interval: $this->options->getInterval() ?? $this->getInterval($this->extractStylingMode($mode)),
interval: $interval,
reversed: $this->options->getReversed(),
);

Expand Down
18 changes: 18 additions & 0 deletions src/Spinner/Core/Palette/PaletteTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,29 @@ public function __construct(
*/
public function getEntries(): Traversable
{
if ($this->options->getReversed()) {
return $this->reversed($this->entries);
}
return $this->entries;
}

public function getOptions(): IPaletteOptions
{
return $this->options;
}

/**
* @param Traversable<IFrame> $entries
* @return Traversable<IFrame>
*/
private function reversed(Traversable $entries): Traversable
{
$sequence = [];

foreach ($entries as $entry) {
$sequence[] = $entry;
}

yield from array_reverse($sequence);
}
}
32 changes: 2 additions & 30 deletions src/Spinner/Core/Palette/Rainbow.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ protected function ansi4StyleFrames(): Traversable
*/
protected function ansi8StyleFrames(): Traversable
{
$sequence = $this->ansi8Sequence();

if ($this->options->getReversed()) {
$sequence = $this->reverseSequence($sequence);
}

/** @var string $item */
foreach ($sequence as $item) {
foreach ($this->ansi8Sequence() as $item) {
$element = sprintf("\e[38;5;%sm%%s\e[39m", $item);
yield $this->createFrame($element);
}
Expand Down Expand Up @@ -79,35 +73,13 @@ private function ansi8Sequence(): Traversable
];
}

/**
* @param Traversable<string> $sequence
*
* @return iterable<string>
*/
private function reverseSequence(Traversable $sequence): iterable
{
/** @var array<string> $s */
$s = [];
/** @var string $item */
foreach ($sequence as $item) {
$s[] = $item;
}
return array_reverse($s);
}

/**
* @return Traversable<IStyleFrame>
*/
protected function ansi24StyleFrames(): Traversable
{
$sequence = $this->ansi24Sequence();

if ($this->options->getReversed()) {
$sequence = $this->reverseSequence($sequence);
}

/** @var string $item */
foreach ($sequence as $item) {
foreach ($this->ansi24Sequence() as $item) {
$element = sprintf("\e[38;2;%sm%%s\e[39m", $item);
yield $this->createFrame($element);
}
Expand Down
Loading

0 comments on commit 0af02cf

Please sign in to comment.