| Total Complexity | 6 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class Component |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $id; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The logger instance. |
||
| 26 | * |
||
| 27 | * @var LoggerInterface |
||
| 28 | */ |
||
| 29 | protected $logger; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | public static function generateUniqueId(): string |
||
| 35 | { |
||
| 36 | return vsprintf('%s.%s', [static::class, uniqid('', true)]); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Constructor. |
||
| 41 | * |
||
| 42 | * @param string|null $id |
||
| 43 | * @param LoggerInterface|null $logger |
||
| 44 | */ |
||
| 45 | public function __construct(?string $id = null, ?LoggerInterface $logger = null) |
||
| 46 | { |
||
| 47 | $this->id = (! empty($id) ? $id : self::generateUniqueId()); |
||
| 48 | $this->logger = (! empty($logger) ? $logger : new NullLogger()); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | public function id(): string |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return void |
||
| 61 | */ |
||
| 62 | public function __destruct() |
||
| 65 | } |
||
| 66 | |||
| 67 | } |
||
| 68 |