Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 52ef18a

Browse files
committed
Merge branch 'release/v0.0.5'
* release/v0.0.5: Bump version Update PHPUnit options Update StyleCI options Update docblock Prepare and tweak testing configuration Add HasSocialAttributes trait Conditionally obscure IDs for if enabled for accessarea Update composer dependencies Drop StyleCI multi-language support (paid feature now!) Add helper function to extract page titles from breadcrumbs Escape only string values, and skip others Rename "escapeRow" method to just "escape" Add row escaper trait Add HashidsTrait Use global helper functions instead of class based methods Add missing composer dependency Drop incomplete Turbolinks-Location redirection and other useless code Update travis php versions
2 parents fb040e2 + 48a9da7 commit 52ef18a

12 files changed

+204
-42
lines changed

.styleci.yml

+42-31
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
1-
php:
2-
preset: recommended
1+
preset: recommended
32

4-
enabled:
5-
- dir_constant
6-
- ereg_to_preg
7-
- mb_str_functions
8-
- no_short_echo_tag
9-
- strict_comparison
10-
- phpdoc_link_to_see
11-
- no_php4_constructor
12-
- declare_strict_types
13-
- unalign_double_arrow
14-
- length_ordered_imports
15-
- modernize_types_casting
16-
- return_type_declaration
17-
- not_operator_with_successor_space
3+
enabled:
4+
- dir_constant
5+
- ereg_to_preg
6+
- no_useless_else
7+
- mb_str_functions
8+
- short_list_syntax
9+
- no_short_echo_tag
10+
- strict_comparison
11+
- phpdoc_link_to_see
12+
- property_separation
13+
- no_php4_constructor
14+
- php_unit_namespaced
15+
- random_api_migration
16+
- declare_strict_types
17+
- unalign_double_arrow
18+
- no_alternative_syntax
19+
- standardize_increment
20+
- length_ordered_imports
21+
- modernize_types_casting
22+
- non_printable_character
23+
- return_type_declaration
24+
- explicit_string_variable
25+
- no_unneeded_final_method
26+
- no_unneeded_curly_braces
27+
- blank_line_before_declare
28+
- compact_nullable_typehint
29+
- combine_consecutive_issets
30+
- combine_consecutive_unsets
31+
- explicit_indirect_variable
32+
- ternary_to_null_coalescing
33+
- escape_implicit_backslashes
34+
- fully_qualified_strict_types
35+
- phpdoc_return_self_reference
36+
- no_null_property_initialization
37+
- multiline_comment_opening_closing
38+
- not_operator_with_successor_space
39+
- phpdoc_add_missing_param_annotation
40+
- php_unit_set_up_tear_down_visibility
1841

19-
disabled:
20-
- align_double_arrow
21-
- alpha_ordered_imports
22-
23-
js:
24-
tab-width: 4
25-
print-width: 120
26-
27-
ts:
28-
tab-width: 4
29-
print-width: 120
30-
31-
css:
32-
tab-width: 4
33-
print-width: 120
42+
disabled:
43+
- align_double_arrow
44+
- alpha_ordered_imports

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
language: php
22

33
php:
4-
- 7.0
54
- 7.1
5+
- 7.2
66

77
env:
88
matrix:
99
- COMPOSER_FLAGS="--prefer-lowest"
1010
- COMPOSER_FLAGS=""
1111

12+
cache:
13+
directories:
14+
- $HOME/.composer/cache
15+
1216
before_script:
1317
- travis_retry composer self-update
1418
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
55
This project adheres to [Semantic Versioning](CONTRIBUTING.md).
66

77

8+
## [v0.0.5] - 2018-09-21
9+
- Update travis php versions
10+
- Drop incomplete Turbolinks-Location redirection and other useless code
11+
- Add missing composer dependency
12+
- Use global helper functions instead of class based methods
13+
- Add HashidsTrait
14+
- Add row escaper trait
15+
- Rename "escapeRow" method to just "escape"
16+
- Escape only string values, and skip others
17+
- Add helper function to extract page titles from breadcrumbs
18+
- Drop StyleCI multi-language support (paid feature now!)
19+
- Update composer dependencies
20+
- Conditionally obscure IDs for if enabled for accessarea
21+
- Add HasSocialAttributes trait
22+
- Prepare and tweak testing configuration
23+
- Update StyleCI options
24+
- Update PHPUnit options
25+
826
## [v0.0.4] - 2018-02-18
927
- Remove duplicate and wrong Asia/Kathmandu timezone
1028
- Add domain helper to get simplify domain host string
@@ -42,6 +60,7 @@ This project adheres to [Semantic Versioning](CONTRIBUTING.md).
4260
## v0.0.1 - 2016-12-20
4361
- Tag first release
4462

63+
[v0.0.5]: https://github.com/rinvex/support/compare/v0.0.4...v0.0.5
4564
[v0.0.4]: https://github.com/rinvex/support/compare/v0.0.3...v0.0.4
4665
[v0.0.3]: https://github.com/rinvex/support/compare/v0.0.2...v0.0.3
4766
[v0.0.2]: https://github.com/rinvex/support/compare/v0.0.1...v0.0.2

composer.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
"illuminate/http": "~5.6.0",
4646
"illuminate/routing": "~5.6.0",
4747
"illuminate/support": "~5.6.0",
48-
"illuminate/validation": "~5.6.0"
48+
"illuminate/validation": "~5.6.0",
49+
"spatie/laravel-schemaless-attributes": "~1.1.0",
50+
"watson/validating": "^3.1.0"
4951
},
5052
"require-dev": {
51-
"codedungeon/phpunit-result-printer": "^0.6.0",
53+
"codedungeon/phpunit-result-printer": "^0.19.0",
5254
"phpunit/phpunit": "^7.0.0"
5355
},
5456
"autoload": {
@@ -59,6 +61,11 @@
5961
"Rinvex\\Support\\": "src/"
6062
}
6163
},
64+
"autoload-dev": {
65+
"psr-4": {
66+
"Rinvex\\Support\\Tests\\": "tests"
67+
}
68+
},
6269
"config": {
6370
"sort-packages": true,
6471
"preferred-install": "dist",

phpunit.xml.dist

+13-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
1616
<testsuites>
1717
<testsuite name="Rinvex Support Unit Test Suite">
18-
<directory>tests</directory>
18+
<directory suffix="Test.php">./tests/Unit</directory>
19+
</testsuite>
20+
<testsuite name="Rinvex Support Feature Test Suite">
21+
<directory suffix="Test.php">./tests/Feature</directory>
1922
</testsuite>
2023
</testsuites>
2124
<filter>
2225
<whitelist>
23-
<directory suffix=".php">src/</directory>
26+
<directory suffix=".php">./src</directory>
2427
</whitelist>
2528
</filter>
2629
<logging>
@@ -30,4 +33,12 @@
3033
<log type="coverage-text" target="build/coverage.txt" />
3134
<log type="coverage-clover" target="build/logs/clover.xml" />
3235
</logging>
36+
<php>
37+
<env name="APP_ENV" value="testing" />
38+
<env name="CACHE_DRIVER" value="array" />
39+
<env name="SESSION_DRIVER" value="array" />
40+
<env name="QUEUE_DRIVER" value="sync" />
41+
<env name="DB_CONNECTION" value="sqlite" />
42+
<env name="DB_DATABASE" value=":memory:" />
43+
</php>
3344
</phpunit>

src/Support/helpers.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
declare(strict_types=1);
44

55
use Illuminate\Support\Str;
6+
use Illuminate\Support\HtmlString;
7+
8+
if (! function_exists('extract_title')) {
9+
/**
10+
* Extract page title from breadcrumbs.
11+
*
12+
* @return string
13+
*/
14+
function extract_title(HtmlString $breadcrumbs, string $separator = ' » ')
15+
{
16+
return strip_tags(str_replace_last($separator, '', str_replace('</li>', $separator, $breadcrumbs)));
17+
}
18+
}
619

720
if (! function_exists('domain')) {
821
/**
@@ -27,20 +40,19 @@ function domain()
2740
*/
2841
function intend(array $arguments, int $status = 302)
2942
{
30-
$redirect = redirect($url = array_pull($arguments, 'url'), $status);
31-
$status = $status ?: (isset($arguments['withErrors']) ? 422 : 200);
43+
$redirect = redirect(array_pull($arguments, 'url'), $status);
3244

3345
if (request()->expectsJson()) {
3446
$response = collect($arguments['withErrors'] ?? $arguments['with']);
3547

36-
return response()->json([$response->flatten()->first() ?? 'OK'], 200)->header('Turbolinks-Location', $url);
48+
return response()->json([$response->flatten()->first() ?? 'OK']);
3749
}
3850

3951
foreach ($arguments as $key => $value) {
4052
$redirect = in_array($key, ['home', 'back']) ? $redirect->{$key}() : $redirect->{$key}($value);
4153
}
4254

43-
return $redirect->header('Turbolinks-Location', $url);
55+
return $redirect;
4456
}
4557
}
4658

src/Traits/Escaper.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rinvex\Support\Traits;
6+
7+
trait Escaper
8+
{
9+
/**
10+
* Escape all values.
11+
*
12+
* @param array $data
13+
*
14+
* @return array
15+
*/
16+
protected function escape(array $data): array
17+
{
18+
$arrayDot = array_filter(array_dot($data));
19+
20+
foreach ($arrayDot as $key => $value) {
21+
if (is_string($value)) {
22+
$arrayDot[$key] = e($value);
23+
}
24+
}
25+
26+
foreach ($arrayDot as $key => $value) {
27+
array_set($data, $key, $value);
28+
}
29+
30+
return $data;
31+
}
32+
}

src/Traits/HasSocialAttributes.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rinvex\Support\Traits;
6+
7+
use Illuminate\Database\Eloquent\Builder;
8+
use Spatie\SchemalessAttributes\SchemalessAttributes;
9+
10+
trait HasSocialAttributes
11+
{
12+
/**
13+
* Get social attributes.
14+
*
15+
* @return \Spatie\SchemalessAttributes\SchemalessAttributes
16+
*/
17+
public function getSocialAttribute(): SchemalessAttributes
18+
{
19+
return SchemalessAttributes::createForModel($this, 'social');
20+
}
21+
22+
/**
23+
* Scope with social attributes.
24+
*
25+
* @return \Illuminate\Database\Eloquent\Builder
26+
*/
27+
public function scopeWithSocial(): Builder
28+
{
29+
return SchemalessAttributes::scopeWithSchemalessAttributes('social');
30+
}
31+
}

src/Traits/HasTranslations.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Rinvex\Support\Traits;
66

7-
use Illuminate\Support\Str;
87
use Spatie\Translatable\Events\TranslationHasBeenSet;
98
use Spatie\Translatable\HasTranslations as BaseHasTranslations;
109

@@ -43,7 +42,7 @@ public function getTranslations($key): array
4342
$oldValue = $value;
4443

4544
if ($this->hasSetMutator($key)) {
46-
$method = 'set'.Str::studly($key).'Attribute';
45+
$method = 'set'.studly_case($key).'Attribute';
4746
$value = $this->{$method}($value);
4847
}
4948

src/Traits/HashidsTrait.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rinvex\Support\Traits;
6+
7+
use Vinkla\Hashids\Facades\Hashids;
8+
9+
trait HashidsTrait
10+
{
11+
/**
12+
* Get the value of the model's route key.
13+
*
14+
* @return mixed
15+
*/
16+
public function getRouteKey()
17+
{
18+
return in_array(request()->route('accessarea'), config('cortex.foundation.obscure'))
19+
? Hashids::encode($this->getAttribute($this->getKeyName()), random_int(1, 999))
20+
: $this->getAttribute($this->getRouteKeyName());
21+
}
22+
23+
/**
24+
* Retrieve the model for a bound value.
25+
*
26+
* @param mixed $value
27+
*
28+
* @return \Illuminate\Database\Eloquent\Model|null
29+
*/
30+
public function resolveRouteBinding($value)
31+
{
32+
return in_array(request()->route('accessarea'), config('cortex.foundation.obscure'))
33+
? $this->where($this->getKeyName(), optional(Hashids::decode($value))[0])->first()
34+
: $this->where($this->getRouteKeyName(), $value)->first();
35+
}
36+
}

tests/Feature/.gitkeep

Whitespace-only changes.

tests/Unit/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)