1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Field\Detectors; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Column; |
6
|
|
|
use Doctrine\DBAL\Types\StringType; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
8
|
|
|
use Terranet\Administrator\Field\Enum; |
9
|
|
|
use function admin\db\connection; |
10
|
|
|
use function admin\db\enum_values; |
11
|
|
|
use function admin\db\translated_values; |
12
|
|
|
|
13
|
|
|
class EnumDetector extends AbstractDetector |
14
|
|
|
{ |
15
|
|
|
/** @var array */ |
16
|
|
|
protected $values = []; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param string $column |
20
|
|
|
* @param Model $model |
21
|
|
|
* @return mixed |
22
|
|
|
*/ |
23
|
|
|
protected function enumValues(string $column, Model $model) |
24
|
|
|
{ |
25
|
|
|
return $this->values = enum_values($model->getTable(), $column); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Authorize execution. |
30
|
|
|
* |
31
|
|
|
* @param string $column |
32
|
|
|
* @param Column $metadata |
33
|
|
|
* @param Model $model |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
|
|
protected function authorize(string $column, Column $metadata, Model $model): bool |
37
|
|
|
{ |
38
|
|
|
return connection('mysql') |
39
|
|
|
&& $metadata->getType() instanceof StringType |
40
|
|
|
&& 0 === (int) $metadata->getLength() |
41
|
|
|
&& !empty($this->enumValues($column, $model)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Detect field class. |
46
|
|
|
* |
47
|
|
|
* @param string $column |
48
|
|
|
* @param Column $metadata |
49
|
|
|
* @param Model $model |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
protected function detect(string $column, Column $metadata, Model $model) |
53
|
|
|
{ |
54
|
|
|
$values = translated_values($this->values, app('scaffold.module')->url(), $column); |
|
|
|
|
55
|
|
|
|
56
|
|
|
if (!$metadata->getNotNull()) { |
57
|
|
|
$values = ['' => '----'] + $values; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return Enum::make($column, $column)->setOptions($values); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths