Skip to content

Commit

Permalink
phpstan level 6, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Nov 3, 2023
1 parent 23b7a4b commit e2c410c
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 228 deletions.
11 changes: 9 additions & 2 deletions .composer-require-checker.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
"pcre",
"session",
"mbstring"

],
"symbol-whitelist": [
"Twig\\Extension\\DebugExtension",
"Illuminate\\Support\\Facades\\DB"
"Twig\\Extension\\AbstractExtension",
"Twig\\Extension\\GlobalsInterface",
"Illuminate\\Support\\Facades\\DB",

"// DI functions",
"DI\\ContainerBuilder",

"// Not detected, do not know why.",
"Psr\\Container\\ContainerInterface"
],
"scan-files": [
"*.php",
Expand Down
68 changes: 2 additions & 66 deletions app/Controllers/ControllerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class ControllerAbstract
*
* @var ContainerInterface
*/
protected $container;
protected ContainerInterface $container;

protected Twig $view;

Expand All @@ -33,75 +33,11 @@ public function __construct(ContainerInterface $container)
unset($container);
}


/**
* Get Slim Container
*
* @return ContainerInterface
*/
protected function getContainer()
{
return $this->container;
}

/**
* Get Service From Container
*
* @param string $service
* @return mixed
*/
protected function getService($service)
{
return $this->container->get($service);
}

/**
* Get Request
*
* @return Request
*/
protected function getRequest()
{
return $this->container->request;
}

/**
* Get Response
*
* @return Response
*/
protected function getResponse()
{
return $this->container->get('response');
}

/**
* Get Twig Engine
*
* @return Twig
*/
/*protected function getView()
{
return $this->container->get(Twig::class);
}*/

/**
* Render view
*
* @param string $template
* @param array $data
* @return string
*/
/*protected function render($template, $data = [])
{
return $this->getView()->render($this->getResponse(), $template, $data);
}*/

/**
* Get a JSON response
*
* @param Response $response Response instance
* @param array $data Data to send
* @param array<mixed, mixed> $data Data to send
* @param int $status HTTP status code
*
* @return Response
Expand Down
12 changes: 7 additions & 5 deletions app/Controllers/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Reference extends ControllerAbstract
{

public function view(Request $request, Response $response)
public function view(Request $request, Response $response): Response
{
$get = $request->getQueryParams();
// default session param for this controller
Expand Down Expand Up @@ -124,7 +124,7 @@ function ($key) use ($join_table) {
return $response;
}

public function register(Request $request, Response $response)
public function register(Request $request, Response $response): Response
{
$post = $request->getParsedBody();

Expand Down Expand Up @@ -166,14 +166,17 @@ public function register(Request $request, Response $response)
$dynamics = $dref->newInstance();
$dynamics->setTable($this->container->get('project')->getSlug() . '_reference');

/** @phpstan-ignore-next-line */
$exists = $dynamics->where('reference_id', $reference['id'])->get();

if (0 === $exists->count()) {
$dyn_data['reference_id'] = $reference['id'];
/** @phpstan-ignore-next-line */
$dynamics->insert(
$dyn_data
);
} else {
/** @phpstan-ignore-next-line */
$dynamics
->where('reference_id', '=', $reference['id'])
->update($dyn_data);
Expand Down Expand Up @@ -203,7 +206,7 @@ public function register(Request $request, Response $response)
);
}

public function filter(Request $request, Response $response)
public function filter(Request $request, Response $response): Response
{
$post = $request->getParsedBody();
if (isset($post['reset_filters'])) {
Expand All @@ -223,7 +226,7 @@ public function filter(Request $request, Response $response)
);
}

public function order(Request $request, Response $response, string $field)
public function order(Request $request, Response $response, string $field): Response
{
if ($_SESSION['reference']['orderby'] == $field) {
// toggle sort if orderby requested on the same column
Expand All @@ -240,5 +243,4 @@ public function order(Request $request, Response $response, string $field)
$this->routeparser->urlFor('reference')
);
}

}
12 changes: 7 additions & 5 deletions app/Controllers/Telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Telemetry extends ControllerAbstract
{

public function view(Request $request, Response $response)
public function view(Request $request, Response $response): Response
{
$get = $request->getQueryParams();
$years = 99;
Expand Down Expand Up @@ -231,7 +231,7 @@ public function view(Request $request, Response $response)
return $response;
}

public function send(Request $request, Response $response)
public function send(Request $request, Response $response): Response
{
$response = $response->withHeader('Content-Type', 'application/json');

Expand Down Expand Up @@ -288,10 +288,12 @@ public function send(Request $request, Response $response)

$json = $json['data'];
$data = $project->mapModel($json);
/** @var TelemetryModel $telemetry_m */
$telemetry_m = TelemetryModel::query()->create($data);

// manage plugins
foreach ($json[$project->getSlug()]['plugins'] as $plugin) {
/** @var GlpiPluginModel $plugin_m */
$plugin_m = GlpiPluginModel::query()->firstOrCreate(['pkey' => $plugin['key']]);

TelemetryGlpiPlugin::query()->create([
Expand All @@ -304,7 +306,7 @@ public function send(Request $request, Response $response)
return $this->withJson($response, ['message' => 'OK']);
}

public function geojson(Request $request, Response $response)
public function geojson(Request $request, Response $response): Response
{
$countries = null;

Expand Down Expand Up @@ -353,15 +355,15 @@ public function geojson(Request $request, Response $response)
return $this->withJson($response, (array)json_decode($countries));
}

public function schema(Request $request, Response $response)
public function schema(Request $request, Response $response): Response
{
//$cache = $this->container->settings->get('debug') == true ? null : $this->container->cache;
$cache = $this->container->get('cache');
$schema = $this->container->get('project')->getSchema($cache);
return $this->withJson($response, $schema);
}

public function allPlugins(Request $request, Response $response)
public function allPlugins(Request $request, Response $response): Response
{
$years = 99;
$get = $request->getQueryParams();
Expand Down
11 changes: 0 additions & 11 deletions app/Middleware/Middleware.php

This file was deleted.

4 changes: 3 additions & 1 deletion app/Models/DynamicReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class DynamicReference extends Model
* Set the table associated with the model.
*
* @param string $table
* @return void
*
* @return self
*/
public function setTable($table)
{
$this->table = $table;
return $this;
}
}
3 changes: 3 additions & 0 deletions app/Models/GlpiPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

use Illuminate\Database\Eloquent\Model;

/**
* @property-read int $id
*/
class GlpiPlugin extends Model
{
protected $table = 'glpi_plugin';
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

use Illuminate\Database\Eloquent\Model;

/**
* @property-read int $id
*/
class Telemetry extends Model
{
protected $table = 'telemetry';
Expand Down
Loading

0 comments on commit e2c410c

Please sign in to comment.