Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6dfff1c
add size method
walmir-silva Jul 1, 2024
18284e0
feat: Normalize Interfaces
walmir-silva Jul 1, 2024
21fc7c0
Merge branch 'main' into develop
walmir-silva Jul 1, 2024
132e0ee
Refactor and Normalize Collection Interface and Implementation
walmir-silva Jul 1, 2024
1124a8a
Merge branch 'main' into develop
walmir-silva Jul 1, 2024
f40b0c3
feat: Add BinaryHeap implementation and comprehensive tests
walmir-silva Jul 2, 2024
aaeb8d9
docs: Update README files in English and Portuguese
walmir-silva Jul 2, 2024
b1d7662
style: Normalize code formatting and style
walmir-silva Jul 2, 2024
d677ae5
Merge branch 'main' into develop
walmir-silva Jul 2, 2024
ff2922f
feat: Create Container interface and add unit tests
walmir-silva Jul 5, 2024
8316540
feat: Add logging interfaces and corresponding tests
walmir-silva Jul 5, 2024
fd0cb1c
feat: Update logging interfaces Add tests for LoggerAware and LoggerC…
walmir-silva Jul 10, 2024
1b46d44
Merge branch 'main' into develop
walmir-silva Jul 10, 2024
30dd462
feat(logging): improve log rotation and update log handler
walmir-silva Jul 18, 2024
fc2bbe3
Refactor:Indexable interface and LogLevel class
walmir-silva Oct 10, 2024
c00bfdc
Merge branch 'main' into develop
walmir-silva Oct 10, 2024
788e773
feat(contract): Add Processor interfaces and tests
walmir-silva Oct 13, 2024
b40023f
feat: add ProcessorRegistry interface and unit tests
walmir-silva Oct 13, 2024
468dc9a
Merge branch 'main' into develop
walmir-silva Oct 13, 2024
9e223a4
feat(processor): add ProcessorBuilder interface and test suite
walmir-silva Oct 14, 2024
3da44b1
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 14, 2024
611e84f
feat(contract): add PHPDoc for ProcessableAttribute interface and cre…
walmir-silva Oct 15, 2024
185bd7c
Merge branch 'main' into develop
walmir-silva Oct 15, 2024
bf99f58
feat(contract): add Sanitizer, Serializer, and Validator interfaces w…
walmir-silva Oct 15, 2024
3e56162
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 15, 2024
b1a9521
fix(validator): correct return type of Validator interface
walmir-silva Oct 15, 2024
115cad9
Merge branch 'main' into develop
walmir-silva Oct 15, 2024
2fcec44
feat(contract): add CustomizableMessageAttribute interface
walmir-silva Oct 18, 2024
c6758d7
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 18, 2024
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
29 changes: 29 additions & 0 deletions src/Processor/Attribute/CustomizableMessageAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Processor\Attribute;

/**
* Interface CustomizableMessageAttribute.
*
* Defines the contract for an attribute that can provide custom error messages for validators.
*
* @category Processor
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
*
* @see https://kariricode.org/
*/
interface CustomizableMessageAttribute
{
/**
* Retrieves a custom message for a specific validator.
*
* @param string $validatorName The name of the validator
*
* @return string|null The custom message if set, null otherwise
*/
public function getMessage(string $validatorName): ?string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace KaririCode\Contract\Processor;
namespace KaririCode\Contract\Processor\Attribute;

/**
* Interface ProcessableAttribute.
Expand All @@ -24,11 +24,4 @@ interface ProcessableAttribute
* @return array The list of processors
*/
public function getProcessors(): array;

/**
* Provides a fallback value for the attribute if processing fails or is not available.
*
* @return mixed The fallback value
*/
public function getFallbackValue(): mixed;
}
6 changes: 3 additions & 3 deletions src/Validator/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
interface Validator
{
/**
* Validates the provided input and returns a boolean indicating if the input is valid.
* Validates the provided input and returns the validated result.
*
* @param mixed $input The value to be validated
*
* @return bool True if the input is valid, false otherwise
* @return mixed The validated result
*/
public function validate(mixed $input): bool;
public function validate(mixed $input): mixed;
}
43 changes: 43 additions & 0 deletions tests/Processor/Attribute/CustomizableMessageAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Tests\Processor\Attribute;

use KaririCode\Contract\Processor\Attribute\CustomizableMessageAttribute;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

final class CustomizableMessageAttributeTest extends TestCase
{
public function testGetMessage(): void
{
/** @var CustomizableMessageAttribute|MockObject */
$customizableMessageAttribute = $this->createMock(CustomizableMessageAttribute::class);

$validatorName = 'requiredValidator';
$expectedMessage = 'This field is required.';

$customizableMessageAttribute->expects($this->once())
->method('getMessage')
->with($validatorName)
->willReturn($expectedMessage);

$this->assertSame($expectedMessage, $customizableMessageAttribute->getMessage($validatorName));
}

public function testGetMessageReturnsNull(): void
{
/** @var CustomizableMessageAttribute|MockObject */
$customizableMessageAttribute = $this->createMock(CustomizableMessageAttribute::class);

$validatorName = 'nonExistentValidator';

$customizableMessageAttribute->expects($this->once())
->method('getMessage')
->with($validatorName)
->willReturn(null);

$this->assertNull($customizableMessageAttribute->getMessage($validatorName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace KaririCode\Contract\Tests\Processor;
namespace KaririCode\Contract\Tests\Processor\Attribute;

use KaririCode\Contract\Processor\ProcessableAttribute;
use KaririCode\Contract\Processor\Attribute\ProcessableAttribute;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -22,17 +22,4 @@ public function testGetProcessors(): void

$this->assertSame($processors, $processableAttribute->getProcessors());
}

public function testGetFallbackValue(): void
{
/** @var ProcessableAttribute|MockObject */
$processableAttribute = $this->createMock(ProcessableAttribute::class);
$fallbackValue = 'default value';

$processableAttribute->expects($this->once())
->method('getFallbackValue')
->willReturn($fallbackValue);

$this->assertSame($fallbackValue, $processableAttribute->getFallbackValue());
}
}
Loading