Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DefaultValueHandler
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
4.07
0.00% covered (danger)
0.00%
0 / 1
 apply
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 properties
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Field\Schema;
6
7use Cosray\Exception\RuntimeException;
8use Cosray\Field\Capability\Defaultable;
9use Cosray\Field\Field;
10
11class DefaultValueHandler extends Handler
12{
13    public function apply(object $meta, Field $field): void
14    {
15        if ($field instanceof Defaultable) {
16            $default = $meta->default;
17            $field->default(is_callable($default) ? $default() : $default);
18
19            return;
20        }
21
22        throw new RuntimeException($this->capabilityErrorMessage($field, Defaultable::class));
23    }
24
25    public function properties(object $meta, Field $field): array
26    {
27        return [];
28    }
29}