We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php namespace Backpack\CRUD; |
||
| 8 | trait CrudTrait { |
||
| 9 | |||
| 10 | /* |
||
| 11 | |-------------------------------------------------------------------------- |
||
| 12 | | Methods for ENUM and SELECT crud fields. |
||
| 13 | |-------------------------------------------------------------------------- |
||
| 14 | */ |
||
| 15 | |||
| 16 | public static function getPossibleEnumValues($field_name){ |
||
| 17 | $instance = new static; // create an instance of the model to be able to get the table name |
||
| 18 | $type = DB::select( DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"') )[0]->Type; |
||
|
|
|||
| 19 | preg_match('/^enum\((.*)\)$/', $type, $matches); |
||
| 20 | $enum = array(); |
||
| 21 | $exploded = explode(',', $matches[1]); |
||
| 22 | foreach($exploded as $value){ |
||
| 23 | $v = trim( $value, "'" ); |
||
| 24 | $enum[] = $v; |
||
| 25 | } |
||
| 26 | return $enum; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function isColumnNullable($column_name) { |
||
| 30 | $instance = new static; // create an instance of the model to be able to get the table name |
||
| 31 | $answer = DB::select(DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'"))[0]; |
||
| 32 | |||
| 33 | return ($answer->IS_NULLABLE == 'YES' ? true : false); |
||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | /* |
||
| 38 | |-------------------------------------------------------------------------- |
||
| 39 | | Methods for Fake Fields functionality (used in PageManager). |
||
| 40 | |-------------------------------------------------------------------------- |
||
| 41 | */ |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Add fake fields as regular attributes, even though they are stored as JSON. |
||
| 45 | * |
||
| 46 | * @param array $columns - the database columns that contain the JSONs |
||
| 47 | */ |
||
| 48 | public function addFakes($columns = ['extras']) { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Return the entity with fake fields as attributes. |
||
| 69 | * |
||
| 70 | * @param array $columns - the database columns that contain the JSONs |
||
| 71 | * @return CrudTrait |
||
| 72 | */ |
||
| 73 | public function withFakes($columns = []) |
||
| 74 | { |
||
| 75 | $model = '\\'.get_class($this); |
||
| 76 | |||
| 77 | if (!count($columns)) { |
||
| 78 | if (property_exists($model, 'fakeColumns')) { |
||
| 79 | $columns = $this->fakeColumns; |
||
|
1 ignored issue
–
show
|
|||
| 80 | } else |
||
| 81 | { |
||
| 82 | $columns = ['extras']; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | $this->addFakes($columns); |
||
| 87 | |||
| 88 | return $this; |
||
| 89 | } |
||
| 90 | |||
| 91 | /* |
||
| 92 | |-------------------------------------------------------------------------- |
||
| 93 | | Translation Methods |
||
| 94 | |-------------------------------------------------------------------------- |
||
| 95 | */ |
||
| 96 | |||
| 97 | public function translations() |
||
| 108 | |||
| 109 | // get translations plus current item, plus original |
||
| 110 | public function allTranslations() |
||
| 111 | { |
||
| 135 | |||
| 136 | public function translation($translation_lang = false) |
||
| 150 | |||
| 151 | public function translationLanguages() |
||
| 167 | |||
| 168 | public function language() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Overwriting the Eloquent save() method, to set a default translation language, if necessary. |
||
| 175 | */ |
||
| 176 | public function save(array $options = []) |
||
| 191 | |||
| 192 | } |
||
| 193 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.