Skip to content

Commit

Permalink
phpstan (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanediondev authored Sep 3, 2023
1 parent 6c4503e commit 7a76dda
Show file tree
Hide file tree
Showing 36 changed files with 265 additions and 157 deletions.
24 changes: 10 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,24 @@ jobs:

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: ${{ matrix.stack-version }}
port: 9200

- name: Sleep for 20 seconds
uses: jakejarvis/wait-action@master
with:
time: '20s'
stack-version: ${{ matrix.stack-version }}
security-enabled: false
port: 9200

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: 8.2
php-version: 8.2
env:
ELASTICSEARCH_URL: 127.0.0.1:9200
ELASTICSEARCH_URL: 127.0.0.1:9200

- name: Validate composer.json and composer.lock
run: composer validate
Expand All @@ -51,7 +47,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- run: npm install
- run: npm run build
Expand Down
21 changes: 14 additions & 7 deletions src/Controller/AppExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@ public function read(Request $request, FlattenException $exception, RequestStack
}

if (500 == $exception->getStatusCode()) {
$dd = new DeviceDetector($request->headers->get('User-Agent'));
$dd->skipBotDetection();
$dd->parse();
if ($request->headers->get('User-Agent')) {
$dd = new DeviceDetector($request->headers->get('User-Agent'));
$dd->skipBotDetection();
$dd->parse();

$client = $dd->getClient();
$os = $dd->getOs();
$client = $dd->getClient();
$os = $dd->getOs();

$parameters['client'] = $client ? $client['name'].' '.$client['version'] : false;
$parameters['os'] = $os ? $os['name'].' '.$os['version'] : false;
if ($client && true === isset($client['name']) && true === isset($client['version'])) {
$parameters['client'] = $client['name'].' '.$client['version'];
}

if ($os && true === isset($os['name']) && true === isset($os['version'])) {
$parameters['os'] = $os['name'].' '.$os['version'];
}
}

$parameters['message'] = $exception->getMessage();
$parameters['file'] = $exception->getFile();
Expand Down
47 changes: 25 additions & 22 deletions src/Controller/AppScreenshotsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,40 @@ public function index(Request $request, string $appEnv): Response
['title' => 'Roles', 'filename' => 'elasticsearch-roles', 'path' => '/admin/elasticsearch-roles', 'feature' => 'security'],
];

$results = [];

$fp = fopen($folder.'/README.md', 'w');

fwrite($fp, '## Screenshots '.$version.'.x');
fwrite($fp, "\r\n");
fwrite($fp, "\r\n");
if ($fp) {
fwrite($fp, '## Screenshots '.$version.'.x');
fwrite($fp, "\r\n");
fwrite($fp, "\r\n");

$results = [];
foreach ($entries as $entry) {
$disabled = false;
foreach ($entries as $entry) {
$disabled = false;

if ('repository-create-s3' == $entry['filename'] && false === $this->callManager->hasPlugin('repository-s3')) {
$disabled = true;
}
if ('repository-create-s3' == $entry['filename'] && false === $this->callManager->hasPlugin('repository-s3')) {
$disabled = true;
}

if (true === isset($entry['feature']) && false === $this->callManager->hasFeature($entry['feature'])) {
$disabled = true;
}
if (true === isset($entry['feature']) && false === $this->callManager->hasFeature($entry['feature'])) {
$disabled = true;
}

if (false === $disabled) {
fwrite($fp, '[![elasticsearch-admin - '.$entry['title'].'](https://raw.githubusercontent.com/stephanediondev/elasticsearch-admin/main/screenshots/'.$version.'/resized/resized-'.$entry['filename'].'.png)](https://raw.githubusercontent.com/stephanediondev/elasticsearch-admin/main/screenshots/'.$version.'/original/original-'.$entry['filename'].'.png)');
fwrite($fp, "\r\n");
fwrite($fp, "\r\n");
if (false === $disabled) {
fwrite($fp, '[![elasticsearch-admin - '.$entry['title'].'](https://raw.githubusercontent.com/stephanediondev/elasticsearch-admin/main/screenshots/'.$version.'/resized/resized-'.$entry['filename'].'.png)](https://raw.githubusercontent.com/stephanediondev/elasticsearch-admin/main/screenshots/'.$version.'/original/original-'.$entry['filename'].'.png)');
fwrite($fp, "\r\n");
fwrite($fp, "\r\n");

$results[] = [
'pageres' => 'pageres '.$base.$entry['path'].' 1280x960 --crop --filename=screenshots/'.$version.'/original/original-'.$entry['filename'].' --overwrite --cookie=\'PHPSESSID='.$cookie.'\'',
'convert' => 'convert -resize 800x600 screenshots/'.$version.'/original/original-'.$entry['filename'].'.png screenshots/'.$version.'/resized/resized-'.$entry['filename'].'.png',
];
$results[] = [
'pageres' => 'pageres '.$base.$entry['path'].' 1280x960 --crop --filename=screenshots/'.$version.'/original/original-'.$entry['filename'].' --overwrite --cookie=\'PHPSESSID='.$cookie.'\'',
'convert' => 'convert -resize 800x600 screenshots/'.$version.'/original/original-'.$entry['filename'].'.png screenshots/'.$version.'/resized/resized-'.$entry['filename'].'.png',
];
}
}
}

fclose($fp);
fclose($fp);
}

if ('prod' != $appEnv) {
$this->addFlash('warning', 'Set APP_ENV to prod');
Expand Down
54 changes: 32 additions & 22 deletions src/Controller/AppSubscriptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,31 @@ public function create(Request $request, string $type): Response
}
}

$dd = new DeviceDetector($request->headers->get('User-Agent'));
$dd->skipBotDetection();
$dd->parse();

$client = $dd->getClient();
$os = $dd->getOs();

$user = $this->appUserManager->getByEmail($this->getuser()->getUserIdentifier());

$subscription = new AppSubscriptionModel();
$subscription->setUserId($user->getId());
$subscription->setType($type);
$subscription->setIp($request->getClientIp());
$subscription->setOs($os ? $os['name'].' '.$os['version'] : null);
$subscription->setClient($client ? $client['name'].' '.$client['version'] : null);
$subscription->setNotifications(AppNotificationModel::getTypes());

if ($request->headers->get('User-Agent')) {
$dd = new DeviceDetector($request->headers->get('User-Agent'));
$dd->skipBotDetection();
$dd->parse();

$client = $dd->getClient();
$os = $dd->getOs();

if ($client && true === isset($client['name']) && true === isset($client['version'])) {
$subscription->setClient($client['name'].' '.$client['version']);
}

if ($os && true === isset($os['name']) && true === isset($os['version'])) {
$subscription->setOs($os['name'].' '.$os['version']);
}
}

$form = $this->createForm(AppSubscriptionType::class, $subscription, ['type' => $type]);

$form->handleRequest($request);
Expand Down Expand Up @@ -244,19 +252,21 @@ public function test(Request $request, string $id): JsonResponse
'body' => $notification->getContent(),
];

$subcription = Subscription::create([
'endpoint' => $subscription->getEndpoint(),
'publicKey' => $publicKey,
'authToken' => $authenticationSecret,
'contentEncoding' => $contentEncoding,
]);

$report = $webPush->sendOneNotification($subcription, json_encode($payload));

if ($report->isSuccess()) {
$json['message'] = 'Message sent successfully for subscription '.$subscription->getEndpoint().'.';
} else {
$json['message'] = 'Message failed to sent for subscription '.$subscription->getEndpoint().': '.$report->getReason().'.';
if ($jsonEncode = json_encode($payload)) {
$subcription = Subscription::create([
'endpoint' => $subscription->getEndpoint(),
'publicKey' => $publicKey,
'authToken' => $authenticationSecret,
'contentEncoding' => $contentEncoding,
]);

$report = $webPush->sendOneNotification($subcription, $jsonEncode);

if ($report->isSuccess()) {
$json['message'] = 'Message sent successfully for subscription '.$subscription->getEndpoint().'.';
} else {
$json['message'] = 'Message failed to sent for subscription '.$subscription->getEndpoint().': '.$report->getReason().'.';
}
}
}
break;
Expand Down
22 changes: 12 additions & 10 deletions src/Controller/ElasticsearchCatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function export(Request $request): ?StreamedResponse

set_time_limit(0);

$type = $request->query->get('type', 'csv');
$delimiter = $request->query->get('delimiter', ';');
$type = $request->query->getString('type', 'csv');
$delimiter = $request->query->getString('delimiter', ';');

switch ($type) {
case 'xlsx':
Expand Down Expand Up @@ -155,22 +155,24 @@ public function export(Request $request): ?StreamedResponse
$callRequest->setPath('/_cat/'.$catModel->getCommandReplace());
$callRequest->setQuery($query);
$callResponse = $this->callManager->call($callRequest);
$parameters['rows'] = $callResponse->getContent();
if (0 < count($parameters['rows'])) {
$parameters['headers'] = array_keys($parameters['rows'][0]);
$rows = $callResponse->getContent();
if (0 < count($rows)) {
$headers = array_keys($rows[0]);
}

$writer->openToFile('php://output');

$lines = [];

$line = [];
foreach ($parameters['headers'] as $header) {
$line[] = $header;
if (true === isset($headers)) {
$line = [];
foreach ($headers as $header) {
$line[] = $header;
}
$lines[] = WriterEntityFactory::createRowFromArray($line);
}
$lines[] = WriterEntityFactory::createRowFromArray($line);

foreach ($parameters['rows'] as $row) {
foreach ($rows as $row) {
$line = [];
foreach ($row as $column) {
$line[] = $column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function create(Request $request): Response
$template = null;

if ($request->query->get('template')) {
$template = $this->elasticsearchComponentTemplateManager->getByName($request->query->get('template'));
$template = $this->elasticsearchComponentTemplateManager->getByName($request->query->getString('template'));

if (null === $template) {
throw new NotFoundHttpException();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ElasticsearchEnrichController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function create(Request $request): Response
$policy = null;

if ($request->query->get('policy')) {
$policy = $this->elasticsearchEnrichPolicyManager->getByName($request->query->get('policy'));
$policy = $this->elasticsearchEnrichPolicyManager->getByName($request->query->getString('policy'));

if (null === $policy) {
throw new NotFoundHttpException();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ElasticsearchIlmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function create(Request $request): Response
$policy = null;

if ($request->query->get('policy')) {
$policy = $this->elasticsearchIlmPolicyManager->getByName($request->query->get('policy'));
$policy = $this->elasticsearchIlmPolicyManager->getByName($request->query->getString('policy'));

if (null === $policy) {
throw new NotFoundHttpException();
Expand Down
Loading

0 comments on commit 7a76dda

Please sign in to comment.