diff --git a/src/Builder.php b/src/Builder.php index 1b5246e..38a8f82 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -175,7 +175,7 @@ protected function insertI18n(array $values, $key) * Update values in base table. * * @param array $values - * @param $ids + * @param array $ids * * @return mixed */ diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 64aadf7..be99733 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -37,6 +37,7 @@ public function setModel(Eloquent $model) * @param array|mixed $columns * * @return $this + * * @throws \Exception */ public function select($columns = ['*']) @@ -54,6 +55,7 @@ public function select($columns = ['*']) * @param array|mixed $column * * @return $this + * * @throws \Exception */ public function addSelect($column) @@ -71,12 +73,13 @@ public function addSelect($column) * @param $columns * * @return mixed + * * @throws \Exception */ protected function qualifyColumns($columns) { foreach ($columns as &$column) { - if (! in_array($column, $this->model->translatableAttributes())) { + if (!in_array($column, $this->model->translatableAttributes())) { continue; } @@ -100,10 +103,10 @@ protected function qualifyColumns($columns) * @param string $operator * @param mixed $value * @param string $boolean + * * @return Builder|QueryBuilder * * @throws \InvalidArgumentException - * * @throws \Exception */ public function where($column, $operator = null, $value = null, $boolean = 'and') @@ -132,6 +135,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' * @param string $operator * @param mixed $value * @param string $boolean + * * @return Builder|QueryBuilder * * @throws \InvalidArgumentException @@ -166,19 +170,19 @@ public function whereTranslated($column, $operator = null, $value = null, $boole } // If the given operator is not found in the list of valid operators we will - // assume that the developer is just short-cutting the '=' operators and + // assume that the developer is just short-cutting the '=' operators, and // we will set the operators to '=' and set the values appropriately. - if (! in_array(strtolower($operator), $this->operators, true)) { + if (!in_array(strtolower($operator), $this->operators, true)) { [$value, $operator] = [$operator, '=']; } $fallbackColumn = $this->qualifyTranslationColumn($column, true); $column = $this->qualifyTranslationColumn($column); - // Finally we'll check whether we need to consider fallback translations. In + // Finally, we'll check whether we need to consider fallback translations. In // that case we need to create a complex "ifnull" clause, otherwise we can // just prepend the translation alias and add the where clause normally. - if (! $this->model->shouldFallback() || $column instanceof Closure) { + if (!$this->model->shouldFallback() || $column instanceof Closure) { return $this->where($column, $operator, $value, $boolean); } @@ -257,7 +261,7 @@ public function orderByTranslated($column, $direction = 'asc') $fallbackColumn = $this->qualifyTranslationColumn($column, true); $column = $this->qualifyTranslationColumn($column); - if (! $this->model->shouldFallback()) { + if (!$this->model->shouldFallback()) { return $this->orderBy($column, $direction); } diff --git a/src/Translatable.php b/src/Translatable.php index 0eb6518..2808449 100644 --- a/src/Translatable.php +++ b/src/Translatable.php @@ -59,7 +59,7 @@ public static function create(array $attributes = [], $translations = []) * * @return Translatable|string */ - public static function createInLocale($locale, array $attributes = [], $translations = []) + public static function createInLocale(string $locale, array $attributes = [], $translations = []) { $model = (new static($attributes))->setLocale($locale); @@ -90,6 +90,7 @@ public static function forceCreate(array $attributes, $translations = []) /** * Save a new model in provided locale and return the instance. Allow mass-assignment. * + * @param string $locale * @param array $attributes * @param array|string $translations * @@ -113,7 +114,7 @@ public static function forceCreateInLocale($locale, array $attributes, $translat */ public function fresh($with = []) { - if (! $this->exists) { + if (!$this->exists) { return null; } @@ -205,7 +206,7 @@ public function forceSaveTranslation($locale, array $attributes) */ public function fill(array $attributes) { - if (! isset(static::$i18nAttributes[$this->getTable()])) { + if (!isset(static::$i18nAttributes[$this->getTable()])) { $this->initTranslatableAttributes(); } @@ -233,7 +234,7 @@ protected function initTranslatableAttributes() */ protected function getTranslatableAttributesFromSchema() { - if ((! $con = $this->getConnection()) || (! $builder = $con->getSchemaBuilder())) { + if ((!$con = $this->getConnection()) || (!$builder = $con->getSchemaBuilder())) { return []; } @@ -254,13 +255,14 @@ protected function getTranslatableAttributesFromSchema() * Return a collection of translated attributes in a given locale. * * @param $locale + * * @return \Laraplus\Data\TranslationModel|null */ public function translate($locale) { $found = $this->translations->where($this->getLocaleKey(), $locale)->first(); - if (! $found && $this->shouldFallback($locale)) { + if (!$found && $this->shouldFallback($locale)) { return $this->translate($this->getFallbackLocale()); } @@ -325,7 +327,7 @@ public function translationModel() */ public function translatableAttributes() { - if (! isset(static::$i18nAttributes[$this->getTable()])) { + if (!isset(static::$i18nAttributes[$this->getTable()])) { return []; } @@ -347,7 +349,7 @@ public function getLocaleKey() * * @param $locale * - * @return string + * @return $this */ public function setLocale($locale) { @@ -380,7 +382,7 @@ public function getLocale() * * @param $locale * - * @return string + * @return $this */ public function setFallbackLocale($locale) { @@ -428,7 +430,7 @@ public function setOnlyTranslated($onlyTranslated) */ public function getOnlyTranslated() { - if (! is_null($this->overrideOnlyTranslated)) { + if (!is_null($this->overrideOnlyTranslated)) { return $this->overrideOnlyTranslated; } @@ -460,7 +462,7 @@ public function setWithFallback($withFallback) */ public function getWithFallback() { - if (! is_null($this->overrideWithFallback)) { + if (!is_null($this->overrideWithFallback)) { return $this->overrideWithFallback; } @@ -502,7 +504,7 @@ public function getTranslationTableSuffix() } /** - * Should fallback to a primary translation. + * Should fall back to a primary translation. * * @param string|null $locale * @@ -510,7 +512,7 @@ public function getTranslationTableSuffix() */ public function shouldFallback($locale = null) { - if (! $this->getWithFallback() || ! $this->getFallbackLocale()) { + if (!$this->getWithFallback() || !$this->getFallbackLocale()) { return false; } @@ -554,7 +556,7 @@ public function getDirty() { $dirty = parent::getDirty(); - if (! $this->localeChanged) { + if (!$this->localeChanged) { return $dirty; } @@ -580,17 +582,18 @@ public function syncOriginal() } /** - * Prefix column names with translation table instead of model table - * if the given column is translated. + * Prefix column names with the translation table instead of the model table if the given column is translated. + * * @param $column + * * @return string */ public function qualifyColumn($column) { - if (\in_array($column, $this->translatableAttributes(), true)) { + if (in_array($column, $this->translatableAttributes(), true)) { return sprintf('%s.%s', $this->getI18nTable(), $column); } + return parent::qualifyColumn($column); } - } diff --git a/src/TranslatableScope.php b/src/TranslatableScope.php index 7846e37..b0fdeed 100644 --- a/src/TranslatableScope.php +++ b/src/TranslatableScope.php @@ -38,7 +38,7 @@ public function apply(EloquentBuilder $builder, Eloquent $model) $this->i18nTable = $model->getI18nTable(); $this->fallback = $model->getFallbackLocale(); - if (! Str::startsWith($this->table, 'laravel_reserved_')) { + if (!Str::startsWith($this->table, 'laravel_reserved_')) { $this->createJoin($builder, $model); $this->createWhere($builder, $model); $this->createSelect($builder, $model); @@ -74,7 +74,7 @@ protected function createJoin(EloquentBuilder $builder, Eloquent $model) */ protected function getJoinType(Eloquent $model) { - $innerJoin = ! $model->shouldFallback() && $model->getOnlyTranslated(); + $innerJoin = !$model->shouldFallback() && $model->getOnlyTranslated(); return $innerJoin ? 'join' : 'leftJoin'; } @@ -146,7 +146,7 @@ protected function createSelect(EloquentBuilder $builder, Eloquent $model) protected function formatColumns(EloquentBuilder $builder, Eloquent $model) { $map = function ($field) use ($builder, $model) { - if (! $model->shouldFallback()) { + if (!$model->shouldFallback()) { return "{$this->i18nTable}.{$field}"; }