forked from suncat2000/MobileDetectBundle
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade PHPStan from level 1 to level 7
- Loading branch information
Showing
19 changed files
with
247 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
all: test | ||
|
||
phpunit: | ||
php vendor/bin/phpunit | ||
XDEBUG_MODE=coverage | php vendor/bin/phpunit --display-phpunit-deprecations | ||
|
||
lint: | ||
php vendor/bin/php-cs-fixer fix --diff | ||
php vendor/bin/phpcs --report=code | ||
php vendor/bin/phpstan analyse | ||
php vendor/bin/phpstan analyse src tests --level 7 --memory-limit=-1 | ||
|
||
test: lint phpunit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
sonar.projectKey=tattali_MobileDetectBundle | ||
sonar.organization=tattali | ||
|
||
sonar.php.coverage.reportPaths=build/coverage.xml | ||
|
||
# This is the name and version displayed in the SonarCloud UI. | ||
#sonar.projectName=CalendarBundle | ||
#sonar.projectVersion=1.0 | ||
|
||
|
||
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. | ||
sonar.sources=./src | ||
|
||
# Encoding of the source code. Default is default system encoding | ||
#sonar.sourceEncoding=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,20 @@ | |
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
use Symfony\Component\VarDumper\Cloner\Data; | ||
|
||
/** | ||
* @author Jonas HAOUZI <[email protected]> | ||
*/ | ||
class DeviceDataCollector extends DataCollector | ||
{ | ||
/** | ||
* @var DeviceView | ||
* @param array<string, mixed> $redirectConfig | ||
*/ | ||
protected $deviceView; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $redirectConfig; | ||
|
||
public function __construct(DeviceView $deviceView) | ||
{ | ||
$this->deviceView = $deviceView; | ||
public function __construct( | ||
protected readonly DeviceView $deviceView, | ||
protected readonly array $redirectConfig = [], | ||
) { | ||
} | ||
|
||
/** | ||
|
@@ -54,7 +49,7 @@ public function collect( | |
'label' => 'Full', | ||
'link' => $this->generateSwitchLink( | ||
$request, | ||
DeviceView::VIEW_FULL | ||
DeviceView::VIEW_FULL, | ||
), | ||
'isCurrent' => $this->deviceView->isFullView(), | ||
'enabled' => $this->canUseView(DeviceView::VIEW_FULL, $request->getSchemeAndHttpHost()), | ||
|
@@ -64,7 +59,7 @@ public function collect( | |
'label' => 'Tablet', | ||
'link' => $this->generateSwitchLink( | ||
$request, | ||
DeviceView::VIEW_TABLET | ||
DeviceView::VIEW_TABLET, | ||
), | ||
'isCurrent' => $this->deviceView->isTabletView(), | ||
'enabled' => $this->canUseView(DeviceView::VIEW_TABLET, $request->getSchemeAndHttpHost()), | ||
|
@@ -74,7 +69,7 @@ public function collect( | |
'label' => 'Mobile', | ||
'link' => $this->generateSwitchLink( | ||
$request, | ||
DeviceView::VIEW_MOBILE | ||
DeviceView::VIEW_MOBILE, | ||
), | ||
'isCurrent' => $this->deviceView->isMobileView(), | ||
'enabled' => $this->canUseView(DeviceView::VIEW_MOBILE, $request->getSchemeAndHttpHost()), | ||
|
@@ -87,22 +82,23 @@ public function getCurrentView(): string | |
return $this->data['currentView']; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function getViews(): array | ||
{ | ||
return $this->data['views']; | ||
} | ||
|
||
public function setRedirectConfig(array $redirectConfig): void | ||
{ | ||
$this->redirectConfig = $redirectConfig; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'device.collector'; | ||
} | ||
|
||
public function getData(): array | ||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function getData(): array|Data | ||
{ | ||
return $this->data; | ||
} | ||
|
@@ -114,8 +110,7 @@ public function reset(): void | |
|
||
protected function canUseView(string $view, ?string $host): bool | ||
{ | ||
if (!\is_array($this->redirectConfig) | ||
|| !isset($this->redirectConfig[$view]) | ||
if (!isset($this->redirectConfig[$view]) | ||
|| !isset($this->redirectConfig[$view]['is_enabled']) | ||
|| false === $this->redirectConfig[$view]['is_enabled'] | ||
) { | ||
|
@@ -128,7 +123,7 @@ protected function canUseView(string $view, ?string $host): bool | |
&& \in_array($this->redirectConfig[$view]['action'], [RequestResponseListener::REDIRECT, RequestResponseListener::REDIRECT_WITHOUT_PATH], true) | ||
) { | ||
$parseHost = parse_url($this->redirectConfig[$view]['host']); | ||
$redirectHost = $parseHost['scheme'].'://'.$parseHost['host']; | ||
$redirectHost = ($parseHost['scheme'] ?? '').'://'.($parseHost['host'] ?? ''); | ||
if (!empty($parseHost['port'])) { | ||
$redirectHost .= ':'.$parseHost['port']; | ||
} | ||
|
@@ -144,14 +139,14 @@ protected function canUseView(string $view, ?string $host): bool | |
private function generateSwitchLink( | ||
Request $request, | ||
string $view, | ||
): ?string { | ||
): string { | ||
$requestSwitchView = $request->duplicate(); | ||
$requestSwitchView->query->set($this->deviceView->getSwitchParam(), $view); | ||
$requestSwitchView->server->set( | ||
'QUERY_STRING', | ||
Request::normalizeQueryString( | ||
http_build_query($requestSwitchView->query->all()) | ||
) | ||
http_build_query($requestSwitchView->query->all()), | ||
), | ||
); | ||
|
||
return $requestSwitchView->getUri(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.