Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/DataStructure/Behavioral/Indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ interface Indexable
/**
* Retrieves an element at the specified index.
*
* @param int $index The index of the element to retrieve
* @param mixed $index The index of the element to retrieve
*
* @return mixed The element at the specified index
*/
public function get(int $index): mixed;
public function get(mixed $index): mixed;

/**
* Sets an element at the specified index.
*
* @param int $index The index where the element should be set
* @param mixed $element The element to set
*/
public function set(int $index, mixed $element): void;
public function set(mixed $index, mixed $element): void;
}
1 change: 1 addition & 0 deletions src/Logging/LogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function handle(ImmutableValue $record): void;

/**
* Checks whether the handler is handling the given log level.
*
* @param ImmutableValue $record the log record to be processed, represented as an associative array
*/
public function isHandling(ImmutableValue $record): bool;
Expand Down
9 changes: 8 additions & 1 deletion src/Logging/LogLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ interface LogLevel
public function getLevel(): string;

/**
* Gets the log level as a int level
* Gets the color level as a string.
*
* @return string the color level
*/
public function getColor(): string;

/**
* Gets the log level as a int level.
*
* @return int the log level
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/LogRotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
interface LogRotator
{
public function shouldRotate(string $filePath): bool;

/**
* Rotates a log file.
*
Expand All @@ -30,5 +31,4 @@ public function shouldRotate(string $filePath): bool;
* @param string $filename the name of the log file to be rotated
*/
public function rotate(string $filename): void;

}
27 changes: 27 additions & 0 deletions src/Processor/ConfigurableProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Processor;

/**
* Interface ConfigurableProcessor.
*
* Extends the Processor interface to allow configuration of the processor.
*
* @category Processor
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
*
* @see https://kariricode.org/
*/
interface ConfigurableProcessor extends Processor
{
/**
* Configures the processor with the provided options.
*
* @param array $options The configuration options
*/
public function configure(array $options): void;
}
36 changes: 36 additions & 0 deletions src/Processor/Pipeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Processor;

/**
* Interface Pipeline.
*
* Defines the contract for a pipeline that can execute a series of processors.
*
* @category Processor
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
*
* @see https://kariricode.org/
*/
interface Pipeline
{
/**
* Adds a processor to the pipeline.
*
* @param Processor $processor The processor to be added
*/
public function addProcessor(Processor $processor): self;

/**
* Executes the processing pipeline on the provided input.
*
* @param mixed $input The value to be processed by the pipeline
*
* @return mixed The final result after passing through all processors
*/
public function process(mixed $input): mixed;
}
29 changes: 29 additions & 0 deletions src/Processor/Processor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Processor;

/**
* Interface Processor.
*
* Defines the contract for a processor that can transform or validate input data.
*
* @category Processor
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
*
* @see https://kariricode.org/
*/
interface Processor
{
/**
* Processes the provided input and returns the result.
*
* @param mixed $input The value to be processed
*
* @return mixed The result of the processing
*/
public function process(mixed $input): mixed;
}
32 changes: 32 additions & 0 deletions tests/Processor/ConfigurableProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Tests\Processor;

use KaririCode\Contract\Processor\ConfigurableProcessor;
use PHPUnit\Framework\TestCase;

final class ConfigurableProcessorTest extends TestCase
{
public function testConfigure(): void
{
$mock = $this->createMock(ConfigurableProcessor::class);
$mock->expects($this->once())
->method('configure')
->with(['option' => 'value']);

$mock->configure(['option' => 'value']);
}

public function testProcess(): void
{
$mock = $this->createMock(ConfigurableProcessor::class);
$mock->expects($this->once())
->method('process')
->with('input')
->willReturn('output');

$this->assertSame('output', $mock->process('input'));
}
}
36 changes: 36 additions & 0 deletions tests/Processor/PipelineTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Tests\Processor;

use KaririCode\Contract\Processor\Pipeline;
use KaririCode\Contract\Processor\Processor;
use PHPUnit\Framework\TestCase;

final class PipelineTest extends TestCase
{
public function testAddProcessor(): void
{
$mock = $this->createMock(Pipeline::class);
$processor = $this->createMock(Processor::class);

$mock->expects($this->once())
->method('addProcessor')
->with($processor)
->willReturnSelf();

$this->assertSame($mock, $mock->addProcessor($processor));
}

public function testProcess(): void
{
$mock = $this->createMock(Pipeline::class);
$mock->expects($this->once())
->method('process')
->with('input')
->willReturn('output');

$this->assertSame('output', $mock->process('input'));
}
}
22 changes: 22 additions & 0 deletions tests/Processor/ProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Tests\Processor;

use KaririCode\Contract\Processor\Processor;
use PHPUnit\Framework\TestCase;

final class ProcessorTest extends TestCase
{
public function testProcess(): void
{
$mock = $this->createMock(Processor::class);
$mock->expects($this->once())
->method('process')
->with('input')
->willReturn('output');

$this->assertSame('output', $mock->process('input'));
}
}