Skip to content

Commit

Permalink
chore: add static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
jordyvanderhaegen committed Dec 18, 2024
1 parent 5b8ffbb commit b3df72e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 14 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: static-analysis

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
extensions: intl
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Run PHPStan
run: vendor/bin/phpstan --error-format=github
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"require-dev": {
"orchestra/testbench-browser-kit": "^8.5|^9.0",
"phpunit/phpunit": "^10.1"
"phpunit/phpunit": "^10.1",
"phpstan/phpstan": "^2.0"
},
"suggest": {
"ext-intl": "*"
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
level: 5
paths:
- src
- tests
ignoreErrors:
- '#Call to an undefined method Illuminate\\Contracts\\Translation\\Translator::has#'
- '#Call to an undefined static method Illuminate\\Support\\Facades\\Route::localized#'
- '#Argument of an invalid type Illuminate\\Routing\\RouteCollectionInterface supplied for foreach, only iterables are supported#'
2 changes: 1 addition & 1 deletion src/Mcamara/LaravelLocalization/LanguageNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LanguageNegotiator
/**
* Illuminate request class.
*
* @var Illuminate\Foundation\Application
* @var \Illuminate\Foundation\Application
*/
protected $app;

Expand Down
6 changes: 3 additions & 3 deletions src/Mcamara/LaravelLocalization/LaravelLocalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LaravelLocalization
/**
* Current locale.
*
* @var string
* @var string|false
*/
protected $currentLocale = false;

Expand Down Expand Up @@ -267,7 +267,7 @@ public function getURLFromRouteNameTranslated($locale, $transKeyName, $attribute
if ($forceDefaultLocation || !($locale === $this->defaultLocale && $this->hideDefaultLocaleInURL())) {
$route = '/'.$locale;
}
if (\is_string($locale) && $this->translator->has($transKeyName, $locale)) {
if ($this->translator->has($transKeyName, $locale)) {
$translation = $this->translator->get($transKeyName, [], $locale);
$route .= '/'.$translation;

Expand Down Expand Up @@ -480,7 +480,7 @@ public function getCurrentLocale()
/**
* Returns current regional.
*
* @return string current regional
* @return string|null current regional
*/
public function getCurrentLocaleRegional(): string|null
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class LaravelLocalizationMiddlewareBase
/**
* The URIs that should not be localized.
*
* @var array
* @var array|null
*/
protected $except;
protected $except = null;

/**
* Determine if the request has a URI that should not be localized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function handle($request, Closure $next)
}

$params = explode('/', $request->path());
$locale = $request->cookie('locale', false);
$locale = $request->cookie('locale') ?? false;

if (\count($params) > 0 && app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
if (app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
return $next($request)->withCookie(cookie()->forever('locale', $params[0]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function handle($request, Closure $next)
$params = explode('/', $request->path());
$locale = session('locale', false);

if (\count($params) > 0 && app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
if (app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
session(['locale' => $params[0]]);

return $next($request);
Expand Down
8 changes: 4 additions & 4 deletions tests/LaravelLocalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ protected function setUpRoutes(): void

/**
* Create fake request
* @param [type] $method [description]
* @param [type] $content [description]
* @param string $method [description]
* @param mixed $content [description]
* @param string $uri [description]
* @param array $server [description]
* @param array $parameters [description]
* @param array $cookies [description]
* @param array $files [description]
* @return [type] [description]
* @return \Illuminate\Http\Request [description]
*/
protected function createRequest(
$uri = '/test',
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function createRequest(
/**
* Define environment setup.
*
* @param Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
Expand Down

0 comments on commit b3df72e

Please sign in to comment.