elegant-bro / interfaces
Installs: 3 855
Dependents: 7
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 1
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^5.7 || ^6.4 || ^7.0 || ^8.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-11-05 19:27:46 UTC
README
Make your objects elegant
Installation
composer require elegant-bro/interfaces
Basic usage
<?php declare(strict_types=1); use ElegantBro\Interfaces\Stringify; final class MyStringify implements Stringify { /** * @return string * @throws Exception */ public function asString(): string { return "Hello World"; } }
<?php declare(strict_types=1); use ElegantBro\Interfaces\Numeric; final class MyNumeric implements Numeric { /** * @return string * @throws Exception */ public function asNumber(): string { return "5"; } }
<?php declare(strict_types=1); use ElegantBro\Interfaces\Iteratee; final class MyIteratee implements Iteratee { /** * @return Iterator * @throws Exception */ public function asIterator(): Iterator { yield 'foo'; yield 'bar'; } }
<?php declare(strict_types=1); use ElegantBro\Interfaces\Arrayee; final class MyArrayee implements Arrayee { /** * @return array * @throws Exception */ public function asArray(): array { return [1, 2, 3]; } }
<?php declare(strict_types=1); use ElegantBro\Interfaces\Predicate; final class Odd implements Predicate { /** * @var int */ private $val; public function __construct(int $val) { $this->val = $val; } public function asBool() : bool { return 0 !== $this->val % 2; } }