Skip to content

Commit

Permalink
[TASK] Clean up code, harden typing, remove deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
fsuter committed Dec 27, 2022
1 parent 6b98481 commit c0d2006
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 51 deletions.
5 changes: 3 additions & 2 deletions Classes/Exception/ConnectorException.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Exception;

/*
Expand All @@ -16,8 +19,6 @@

/**
* Base class for all Connector-related exceptions.
*
* @package Cobweb\Svconnector\Exception
*/
class ConnectorException extends \Exception
{
Expand Down
5 changes: 3 additions & 2 deletions Classes/Exception/ConnectorRuntimeException.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Exception;

/*
Expand All @@ -17,8 +20,6 @@
/**
* Exception to throw when an error happens while performing
* a non-specific connector operation.
*
* @package Cobweb\Svconnector\Exception
*/
class ConnectorRuntimeException extends ConnectorException
{
Expand Down
5 changes: 3 additions & 2 deletions Classes/Exception/EmptySourceException.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Exception;

/*
Expand All @@ -16,8 +19,6 @@

/**
* Exception to throw when the source of data is empty.
*
* @package Cobweb\Svconnector\Exception
*/
class EmptySourceException extends ConnectorException
{
Expand Down
5 changes: 3 additions & 2 deletions Classes/Exception/InvalidSourceException.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Exception;

/*
Expand All @@ -16,8 +19,6 @@

/**
* Exception to throw when the source contains invalid or malformed data.
*
* @package Cobweb\Svconnector\Exception
*/
class InvalidSourceException extends ConnectorException
{
Expand Down
5 changes: 3 additions & 2 deletions Classes/Exception/SourceErrorException.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Exception;

/*
Expand All @@ -17,8 +20,6 @@
/**
* Exception to throw when an error occurs when trying to access a source of data
* (e.g. a file is not found, a database cannot be accessed, etc.).
*
* @package Cobweb\Svconnector\Exception
*/
class SourceErrorException extends ConnectorException
{
Expand Down
5 changes: 3 additions & 2 deletions Classes/Exception/UnknownServiceException.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Exception;

/*
Expand All @@ -16,8 +19,6 @@

/**
* Exception to throw when an unknown service is requested.
*
* @package Cobweb\Svconnector\Exception
*/
class UnknownServiceException extends ConnectorException
{
Expand Down
8 changes: 4 additions & 4 deletions Classes/Utility/AbstractFileReader.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Utility;

/*
Expand All @@ -17,15 +19,13 @@

/**
* Abstract base class for classes used in the $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['svconnector']['fileReader'] hook.
*
* @package Cobweb\Svconnector\Utility
*/
abstract class AbstractFileReader
{
/**
* @var FileUtility
*/
protected $fileUtility;
protected FileUtility $fileUtility;

public function __construct($fileUtility)
{
Expand All @@ -40,5 +40,5 @@ public function __construct($fileUtility)
* @param string $uri
* @return string
*/
abstract public function read($uri): string;
abstract public function read(string $uri): string;
}
14 changes: 6 additions & 8 deletions Classes/Utility/ConnectorUtility.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Utility;

/*
Expand All @@ -17,10 +19,6 @@

/**
* Utility class for the Connector family of services
*
* @author Francois Suter (Cobweb) <typo3@cobweb.ch>
* @package TYPO3
* @subpackage tx_svconnector
*/
class ConnectorUtility
{
Expand Down Expand Up @@ -73,10 +71,10 @@ class ConnectorUtility
*
* @param string $string XML to parse
* @param int $options LIBXML options for XML parsing (optional)
* @throws \Exception
* @return array PHP array
*@throws \Exception
*/
public static function convertXmlToArray($string, $options = null): array
public static function convertXmlToArray(string $string, int $options = 0): array
{
// If input string is empty, exit with exception
if (empty($string)) {
Expand Down Expand Up @@ -107,7 +105,7 @@ public static function convertXmlToArray($string, $options = null): array
* @param array $namespaces List of namespaces used (optional)
* @return array Transformed XML node and children
*/
public static function handleXmlNode(\SimpleXMLElement $node, $namespaces = [])
public static function handleXmlNode(\SimpleXMLElement $node, array $namespaces = [])
{
// Init
$nodeArray = [];
Expand Down Expand Up @@ -152,7 +150,7 @@ public static function handleXmlNode(\SimpleXMLElement $node, $namespaces = [])
* @param string $namespace Namespace to be parsed (optional)
* @return array
*/
public static function handleChildren(\SimpleXMLElement $node, $namespaces = [], $namespace = null) {
public static function handleChildren(\SimpleXMLElement $node, array $namespaces = [], $namespace = null) {
$children = $node->children($namespace, true);
$array = [];
if ($children->count() > 0) {
Expand Down
10 changes: 5 additions & 5 deletions Classes/Utility/FileUtility.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\Utility;

/*
Expand All @@ -23,8 +25,6 @@

/**
* Class for opening either local or remote files.
*
* @package Cobweb\Svconnector\Utility
*/
class FileUtility implements SingletonInterface
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public function __toString()
* @param array|null $headers Headers to pass on to the request
* @return string|bool
*/
public function getFileContent($uri, $headers = null)
public function getFileContent(string $uri, $headers = null)
{
// Reset the error message
$this->setError('');
Expand Down Expand Up @@ -152,7 +152,7 @@ public function getFileContent($uri, $headers = null)
* @return string|bool
* @see getFileContent
*/
public function getFileAsTemporaryFile($uri, $headers = null)
public function getFileAsTemporaryFile(string $uri, $headers = null)
{
$fileContent = $this->getFileContent($uri, $headers);
// Exit early if file content could not be read
Expand Down Expand Up @@ -194,7 +194,7 @@ public function getError(): string
*
* @param string $error
*/
public function setError($error)
public function setError(string $error): void
{
$this->error = (string)$error;
}
Expand Down
25 changes: 3 additions & 22 deletions Classes/ViewHelpers/Be/ResultViewHelper.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Cobweb\Svconnector\ViewHelpers\Be;

/*
Expand All @@ -20,10 +23,6 @@

/**
* This view helper is designed to output the result of the connection test appropriately, depending on its format
*
* @author Francois Suter (Cobweb) <typo3@cobweb.ch>
* @package TYPO3
* @subpackage tx_svconnector
*/
class ResultViewHelper extends AbstractBackendViewHelper
{
Expand All @@ -44,24 +43,6 @@ public function initializeArguments()
$this->registerArgument('result', 'mixed', 'Result of the connection test', true);
}

/**
* Renders whatever result the connection test returned.
*
* TODO: remove when v8 compatibility is dropped.
*
* @return string
*/
public function render()
{
return static::renderStatic(
[
'result' => $this->arguments['result']
],
$this->buildRenderChildrenClosure(),
$this->renderingContext
);
}

/**
* Renders whatever result the connection test returned.
*
Expand Down

0 comments on commit c0d2006

Please sign in to comment.