Skip to content

Commit d13e12f

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into issue-309
2 parents 912c42c + 6111ef7 commit d13e12f

File tree

9 files changed

+168
-29
lines changed

9 files changed

+168
-29
lines changed

.codeclimate.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: "2"
2+
checks:
3+
argument-count:
4+
enabled: true
5+
config:
6+
threshold: 6
7+
complex-logic:
8+
enabled: true
9+
file-lines:
10+
enabled: false
11+
method-complexity:
12+
enabled: true
13+
method-count:
14+
enabled: true
15+
method-lines:
16+
enabled: true
17+
nested-control-flow:
18+
enabled: true
19+
return-statements:
20+
enabled: true
21+
similar-code:
22+
enabled: true
23+
identical-code:
24+
enabled: true
25+
plugins:
26+
phpcodesniffer:
27+
enabled: true
28+
config:
29+
file_extensions:
30+
- php
31+
phpmd:
32+
enabled: true
33+
config:
34+
file_extensions:
35+
- php
36+
checks:
37+
CleanCode/StaticAccess:
38+
enabled: false
39+
Design/TooManyPublicMethods:
40+
enabled: false
41+
phan:
42+
enabled: false

.github/stale.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 14
3+
# Number of days of inactivity before a stale issue is closed
4+
daysUntilClose: 28
5+
# Issues with these labels will never be considered stale
6+
exemptLabels:
7+
- next release
8+
- next major release
9+
- help wanted
10+
# Label to use when marking an issue as stale
11+
staleLabel: stale
12+
# Comment to post when marking an issue as stale. Set to `false` to disable
13+
markComment: >
14+
This issue has been automatically marked as stale because it has not had recent activity.
15+
It will be closed if no further activity occurs.
16+
Thank you for your contributions.
17+
# Comment to post when closing a stale issue. Set to `false` to disable
18+
closeComment: >
19+
This issue has been automatically closed because it has not had recent activity.
20+
Thank you for your contributions.

.scrutinizer.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ build:
1515

1616
tools:
1717
external_code_coverage:
18-
timeout: 3600
18+
timeout: 900
1919
runs: 4
20+
21+
filter:
22+
paths:
23+
- src/
24+
excluded_paths:
25+
- tests/

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
},
2323
"require": {
2424
"php": ">=7.1.3",
25+
"illuminate/contracts": "5.6.*|5.7.*|5.8.*",
26+
"illuminate/database": "5.6.*|5.7.*|5.8.*",
2527
"illuminate/support": "5.6.*|5.7.*|5.8.*"
2628
},
2729
"require-dev": {

docs/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Introduction
22

3-
[![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) [![CircleCI](https://img.shields.io/circleci/build/github/Astrotomic/laravel-translatable/master.svg?label=CircleCI&style=flat-square)](https://circleci.com/gh/Astrotomic/laravel-translatable) [![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549) [![Code Quality](https://img.shields.io/scrutinizer/quality/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/) [![Latest Version](http://img.shields.io/packagist/v/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) ![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-translatable.svg?color=blue&style=flat-square)
3+
[![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable)
4+
[![CircleCI](https://img.shields.io/circleci/build/github/Astrotomic/laravel-translatable/master.svg?label=CircleCI&style=flat-square)](https://circleci.com/gh/Astrotomic/laravel-translatable)
5+
[![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549)
6+
[![ScrutinizerCI](https://img.shields.io/scrutinizer/quality/g/Astrotomic/laravel-translatable/master.svg?label=ScrutinizerCI&style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/)
7+
[![Code Climate](https://img.shields.io/codeclimate/maintainability/Astrotomic/laravel-translatable.svg?label=CodeClimate&style=flat-square)](https://codeclimate.com/github/Astrotomic/laravel-translatable)
8+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/)
9+
[![Latest Version](http://img.shields.io/packagist/v/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable)
10+
![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-translatable.svg?color=blue&style=flat-square)
411

512
![](.gitbook/assets/laravel-translatable.png)
613

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Laravel-Translatable
44
[![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable)
55
[![CircleCI](https://img.shields.io/circleci/build/github/Astrotomic/laravel-translatable/master.svg?label=CircleCI&style=flat-square)](https://circleci.com/gh/Astrotomic/laravel-translatable)
66
[![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549)
7-
[![Code Quality](https://img.shields.io/scrutinizer/quality/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/)
7+
[![ScrutinizerCI](https://img.shields.io/scrutinizer/quality/g/Astrotomic/laravel-translatable/master.svg?label=ScrutinizerCI&style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/)
8+
[![Code Climate](https://img.shields.io/codeclimate/maintainability/Astrotomic/laravel-translatable.svg?label=CodeClimate&style=flat-square)](https://codeclimate.com/github/Astrotomic/laravel-translatable)
89
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/)
910
[![Latest Version](http://img.shields.io/packagist/v/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable)
1011
![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-translatable.svg?color=blue&style=flat-square)

src/Translatable/Locales.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function load(): void
4949
$countryLocale = $this->getCountryLocale($key, $country);
5050
$this->locales[$countryLocale] = $countryLocale;
5151
}
52-
} else {
52+
} elseif (is_string($locale)) {
5353
$this->locales[$locale] = $locale;
5454
}
5555
}

src/Translatable/Translatable.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ public function setAttribute($key, $value)
199199

200200
if ($this->isTranslationAttribute($attribute)) {
201201
$this->getTranslationOrNew($locale)->$attribute = $value;
202-
} else {
203-
return parent::setAttribute($key, $value);
202+
203+
return $this;
204204
}
205205

206-
return $this;
206+
return parent::setAttribute($key, $value);
207207
}
208208

209209
protected function getTranslationOrNew(?string $locale = null): Model
@@ -419,44 +419,29 @@ public function scopeWithTranslation(Builder $query)
419419
]);
420420
}
421421

422-
public function scopeWhereTranslation(Builder $query, string $translationField, $value, ?string $locale = null)
422+
public function scopeWhereTranslation(Builder $query, string $translationField, $value, ?string $locale = null, string $method = 'whereHas', string $operator = '=')
423423
{
424-
return $query->whereHas('translations', function (Builder $query) use ($translationField, $value, $locale) {
425-
$query->where($this->getTranslationsTable().'.'.$translationField, $value);
424+
return $query->$method('translations', function (Builder $query) use ($translationField, $value, $locale, $operator) {
425+
$query->where($this->getTranslationsTable().'.'.$translationField, $operator, $value);
426426
if ($locale) {
427-
$query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $locale);
427+
$query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $operator, $locale);
428428
}
429429
});
430430
}
431431

432432
public function scopeOrWhereTranslation(Builder $query, string $translationField, $value, ?string $locale = null)
433433
{
434-
return $query->orWhereHas('translations', function (Builder $query) use ($translationField, $value, $locale) {
435-
$query->where($this->getTranslationsTable().'.'.$translationField, $value);
436-
if ($locale) {
437-
$query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $locale);
438-
}
439-
});
434+
return $this->scopeWhereTranslation($query, $translationField, $value, $locale, 'orWhereHas');
440435
}
441436

442437
public function scopeWhereTranslationLike(Builder $query, string $translationField, $value, ?string $locale = null)
443438
{
444-
return $query->whereHas('translations', function (Builder $query) use ($translationField, $value, $locale) {
445-
$query->where($this->getTranslationsTable().'.'.$translationField, 'LIKE', $value);
446-
if ($locale) {
447-
$query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), 'LIKE', $locale);
448-
}
449-
});
439+
return $this->scopeWhereTranslation($query, $translationField, $value, $locale, 'whereHas', 'LIKE');
450440
}
451441

452442
public function scopeOrWhereTranslationLike(Builder $query, string $translationField, $value, ?string $locale = null)
453443
{
454-
return $query->orWhereHas('translations', function (Builder $query) use ($translationField, $value, $locale) {
455-
$query->where($this->getTranslationsTable().'.'.$translationField, 'LIKE', $value);
456-
if ($locale) {
457-
$query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), 'LIKE', $locale);
458-
}
459-
});
444+
return $this->scopeWhereTranslation($query, $translationField, $value, $locale, 'orWhereHas', 'LIKE');
460445
}
461446

462447
public function scopeOrderByTranslation(Builder $query, string $translationField, string $sortMethod = 'asc')

0 commit comments

Comments
 (0)