Skip to content

Commit

Permalink
Cleanup, missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Nov 2, 2023
1 parent 7fe3157 commit 07c15d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 91 deletions.
66 changes: 1 addition & 65 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,70 +33,6 @@ 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
*
Expand Down
9 changes: 4 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 @@ -203,7 +203,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 +223,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 +240,4 @@ public function order(Request $request, Response $response, string $field)
$this->routeparser->urlFor('reference')
);
}

}
10 changes: 5 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 @@ -304,7 +304,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 +353,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
24 changes: 12 additions & 12 deletions app/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct($logger = null)
*
* @return Project
*/
public function setConfig($config)
public function setConfig(array $config): self
{
$this->checkConfig($config);

Expand Down Expand Up @@ -152,13 +152,13 @@ private function setSchemaConfig($config)
}

/**
* Generate or retrieve project's schema
* Generate or retrieve project's schema as JSON
*
* @param Laminas\Cache\Storage\Adapter\AbstractAdapter|null $cache Cache instance
*
* @return json
* @return string
*/
public function getSchema($cache)
public function getSchema($cache): string
{
if (null != $cache && $cache->hasItem('schema')) {
$schema = $cache->getItem($this->getSlug() . '_schema.json');
Expand Down Expand Up @@ -241,7 +241,7 @@ public function getSchema($cache)
*
* @return array
*/
public function mapModel($json)
public function mapModel(array $json): array
{
$slug = $this->getSlug();

Expand Down Expand Up @@ -306,7 +306,7 @@ public function mapModel($json)
*
* @return string
*/
public function truncate($string, $length)
public function truncate(string $string, int $length): string
{
if (mb_strlen($string) > $length) {
if ($this->logger !== null) {
Expand All @@ -325,7 +325,7 @@ public function truncate($string, $length)
*
* @return string
*/
public function getSlug()
public function getSlug(): string
{
return $this->slug;
}
Expand All @@ -335,7 +335,7 @@ public function getSlug()
*
* @return string
*/
public function getURL()
public function getURL(): string
{
return $this->url;
}
Expand All @@ -345,7 +345,7 @@ public function getURL()
*
* @return array
*/
public function getFooterLinks()
public function getFooterLinks(): array
{
return $this->footer_links;
}
Expand All @@ -355,17 +355,17 @@ public function getFooterLinks()
*
* @return array
*/
public function getSocialLinks()
public function getSocialLinks(): array
{
return $this->social_links;
}

/**
* Get dynamic references
*
* @return array|false
* @return array
*/
public function getDynamicReferences()
public function getDynamicReferences(): array
{
return $this->dyn_references;
}
Expand Down
4 changes: 0 additions & 4 deletions app/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@

$app->addRoutingMiddleware();

// init slim
/*$app = new \Slim\App(["settings" => $config]);
$container = $app->getContainer();*/

$container->set('mail_from', $config['mail_from']);
$container->set('mail_admin', $config['mail_admin']);
$container->set('is_debug', $config['debug']);
Expand Down

0 comments on commit 07c15d9

Please sign in to comment.