Skip to content

Commit

Permalink
chore: apply PSR-12 manual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed May 30, 2023
1 parent b7b6a3b commit 700d6e0
Show file tree
Hide file tree
Showing 70 changed files with 574 additions and 131 deletions.
5 changes: 4 additions & 1 deletion common/cache/class.KeyValueCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class common_cache_KeyValueCache extends ConfigurableService implements common_c
protected function getPersistence()
{
if (is_null($this->persistence)) {
$this->persistence = $this->getServiceLocator()->get('generis/persistences')->getPersistenceById($this->getOption(self::OPTION_PERSISTENCE));
$this->persistence = $this
->getServiceLocator()
->get('generis/persistences')
->getPersistenceById($this->getOption(self::OPTION_PERSISTENCE));
}
return $this->persistence;
}
Expand Down
5 changes: 4 additions & 1 deletion common/cache/class.PartitionedCachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public function __sleep()
}
}
if ($containsNonSerializable && $containsSerializable) {
throw new common_exception_Error('Serializable ' . $this->getSerial() . ' mixed serializable and non serializable values in property ' . $propertyName);
throw new common_exception_Error(
'Serializable ' . $this->getSerial()
. ' mixed serializable and non serializable values in property ' . $propertyName
);
}
} else {
if (is_object($value) && $value instanceof self) {
Expand Down
6 changes: 5 additions & 1 deletion common/class.Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ public function intersect(common_Collection $collection)


$returnValue = new common_Collection(new common_Object(__METHOD__));
$returnValue->sequence = array_uintersect($this->sequence, $collection->sequence, 'core_kernel_classes_ContainerComparator::compare');
$returnValue->sequence = array_uintersect(
$this->sequence,
$collection->sequence,
'core_kernel_classes_ContainerComparator::compare'
);


return $returnValue;
Expand Down
12 changes: 10 additions & 2 deletions common/class.Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public static function isUri($strarg)
$returnValue = (bool) false;
$uri = trim($strarg);
if (!empty($uri)) {
if ((preg_match("/^(http|https|file|ftp):\/\/[\/:.A-Za-z0-9_-]+#[A-Za-z0-9_-]+$/", $uri) && strpos($uri, '#') > 0) || strpos($uri, "#") === 0) {
if (
(
preg_match("/^(http|https|file|ftp):\/\/[\/:.A-Za-z0-9_-]+#[A-Za-z0-9_-]+$/", $uri)
&& strpos($uri, '#') > 0
)
|| strpos($uri, "#") === 0
) {
$returnValue = true;
}
}
Expand Down Expand Up @@ -156,7 +162,9 @@ public static function toPHPVariableString($value)
break;
default:
// resource and unexpected types
throw new common_exception_Error("Could not convert variable of type " . gettype($value) . " to PHP variable string");
throw new common_exception_Error(
"Could not convert variable of type " . gettype($value) . " to PHP variable string"
);
}

return (string) $returnValue;
Expand Down
7 changes: 5 additions & 2 deletions common/configuration/class.ComponentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public function check()
array_push($traversed, $node); // mark the node as 'traversed'.

if ($status == common_configuration_Report::VALID) {
$stack = self::pushTransitionsOnStack($stack, $this->getTransitions($node)); // put all transitions from the node to stack.
// put all transitions from the node to stack.
$stack = self::pushTransitionsOnStack($stack, $this->getTransitions($node));

while (count($stack) > 0) {
$transition = array_pop($stack);
Expand All @@ -232,7 +233,9 @@ public function check()

$returnValue = $this->getReports();
} else {
throw new common_configuration_CyclicDependencyException("The dependency graph is cyclic. Please review your dependencies.");
throw new common_configuration_CyclicDependencyException(
"The dependency graph is cyclic. Please review your dependencies."
);
}
}

Expand Down
16 changes: 14 additions & 2 deletions common/configuration/class.ComponentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,15 @@ public static function buildFromArray($array)

if (!empty($array)) {
if (!empty($array['type'])) {
$acceptedTypes = ['PHPRuntime', 'PHPINIValue', 'PHPExtension', 'PHPDatabaseDriver', 'FileSystemComponent', 'Custom', 'Mock'];
$acceptedTypes = [
'PHPRuntime',
'PHPINIValue',
'PHPExtension',
'PHPDatabaseDriver',
'FileSystemComponent',
'Custom',
'Mock'
];
$cleanType = preg_replace('/^Check/i', '', $array['type']);
if (in_array($cleanType, $acceptedTypes)) {
if (!empty($array['value'])) {
Expand Down Expand Up @@ -334,7 +342,11 @@ public static function buildFromArray($array)
throw new common_configuration_ComponentFactoryException($msg);
}

$returnValue = self::buildFileSystemComponent($values['location'], $values['rights'], $optional);
$returnValue = self::buildFileSystemComponent(
$values['location'],
$values['rights'],
$optional
);
break;

case 'Custom':
Expand Down
16 changes: 12 additions & 4 deletions common/configuration/class.FileSystemComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ class common_configuration_FileSystemComponent extends common_configuration_Comp
* @throws common_configuration_MalformedRightsException
* @return mixed
*/
public function __construct($location, $expectedRights, $optional = false, $recursive = false, $mustCheckIfEmpty = false)
{
public function __construct(
$location,
$expectedRights,
$optional = false,
$recursive = false,
$mustCheckIfEmpty = false
) {
parent::__construct('tao.configuration.filesystem', $optional);

$this->setExpectedRights($expectedRights);
Expand Down Expand Up @@ -275,7 +280,8 @@ public function check()

return new common_configuration_Report(
common_configuration_Report::VALID,
"File system component '${name}' in '${location} is compliant with expected rights (${expectedRights}).'",
"File system component '${name}' in '${location} is compliant with expected rights "
. "(${expectedRights}).'",
$this
);
}
Expand Down Expand Up @@ -304,7 +310,9 @@ private function hasLocationAccess($location = null, $rule = 'Readable')
$funcName = 'is_' . strtolower($rule);
$returnValue = $funcName($location);
} else {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($location, \RecursiveDirectoryIterator::SKIP_DOTS));
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($location, \RecursiveDirectoryIterator::SKIP_DOTS)
);

try {
$method = 'is' . $rule;
Expand Down
5 changes: 3 additions & 2 deletions common/configuration/class.Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class common_configuration_Mock extends common_configuration_Component
*
* @access public
* @author Jerome Bogaerts, <[email protected]>
* @param int expectedStatus The expected status of the report that will be provided by the check method. Must correspond to a constant of the Report class.
* @param string name The name of the mock configuration component to make it identifiable among others.
* @param int $expectedStatus The expected status of the report that will be provided by the check method. Must
* correspond to a constant of the Report class.
* @param string $name The name of the mock configuration component to make it identifiable among others.
* @return mixed
*/
public function __construct($expectedStatus, $name)
Expand Down
3 changes: 2 additions & 1 deletion common/exception/class.ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
* @package generis
*/
abstract class common_exception_ClientException extends common_Exception implements common_exception_UserReadableException
abstract class common_exception_ClientException extends common_Exception implements
common_exception_UserReadableException
{
public function __construct($message = null, $code = 0)
{
Expand Down
3 changes: 2 additions & 1 deletion common/exception/class.InvalidArgumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function __construct($class = null, $function = 0, $position = 0, $expect
{

$object = is_object($object) ? get_class($object) : gettype($object);
$message = 'Argument ' . $position . ' passed to ' . $class . '::' . $function . '() must be an ' . $expectedType . ', ' . $object . ' given';
$message = 'Argument ' . $position . ' passed to ' . $class . '::' . $function . '() must be an '
. $expectedType . ', ' . $object . ' given';
parent::__construct($message);
}
}
3 changes: 2 additions & 1 deletion common/exception/class.ResourceNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* Copyright (c) 2019 (original work) Open Assessment Technologies SA ;
*/

class common_exception_ResourceNotFound extends \common_exception_NotFound implements \common_exception_UserReadableException
class common_exception_ResourceNotFound extends \common_exception_NotFound implements
\common_exception_UserReadableException
{
/**
* @inheritdoc
Expand Down
10 changes: 8 additions & 2 deletions common/ext/class.Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ public function getManifest()
if (is_file($manifestFile) && is_readable($manifestFile)) {
$this->manifest = new Manifest($manifestFile);
} else {
throw new ManifestNotFoundException("Extension Manifest not found for extension '" . $this->id . "'.", $this->id);
throw new ManifestNotFoundException(
"Extension Manifest not found for extension '" . $this->id . "'.",
$this->id
);
}
}
$this->manifest->setServiceLocator($this->getServiceLocator());
Expand Down Expand Up @@ -418,7 +421,10 @@ public function load()
$this->getExtensionManager()->getExtensionById($extId);
}
} catch (ManifestNotFoundException $e) {
throw new common_ext_MissingExtensionException($e->getExtensionId() . ' not found but required for ' . $this->getId(), $e->getExtensionId());
throw new common_ext_MissingExtensionException(
$e->getExtensionId() . ' not found but required for ' . $this->getId(),
$e->getExtensionId()
);
}

$loader = new common_ext_ExtensionLoader($this);
Expand Down
5 changes: 4 additions & 1 deletion common/ext/class.ExtensionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ protected function getExtension()
*/
protected function runExtensionScript($script, array $arguments = [])
{
$this->log('d', 'Running custom extension script ' . $script . ' for extension ' . $this->getExtension()->getId());
$this->log(
'd',
'Running custom extension script ' . $script . ' for extension ' . $this->getExtension()->getId()
);
if (file_exists($script)) {
require_once $script;
} elseif (class_exists($script) && is_subclass_of($script, \oat\oatbox\action\Action::class)) {
Expand Down
13 changes: 11 additions & 2 deletions common/ext/class.ExtensionInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,19 @@ protected function installCustomScript()
foreach ($this->extension->getManifest()->getInstallPHPFiles() as $script) {
if (is_string($script)) {
$this->runExtensionScript($script);
} elseif (is_array($script) && isset($script[0]) && is_string($script[0]) && !empty($script[0]) && isset($script[1]) && is_array($script[1])) {
} elseif (
is_array($script)
&& isset($script[0])
&& is_string($script[0])
&& !empty($script[0])
&& isset($script[1])
&& is_array($script[1])
) {
$this->runExtensionScript($script[0], $script[1]);
} else {
\common_Logger::w("Ignored custom install script because it's call definition is malformed in extension manifest!");
\common_Logger::w(
"Ignored custom install script because it's call definition is malformed in extension manifest!"
);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions common/ext/class.ExtensionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ public function addModelFiles($extension)
{
foreach ($extension->getManifest()->getInstallModelFiles() as $rdfpath) {
if (!file_exists($rdfpath)) {
throw new common_ext_InstallationException("Unable to load ontology in '${rdfpath}' because the file does not exist.");
throw new common_ext_InstallationException(
"Unable to load ontology in '${rdfpath}' because the file does not exist."
);
}

if (!is_readable($rdfpath)) {
throw new common_ext_InstallationException("Unable to load ontology in '${rdfpath}' because the file is not readable.");
throw new common_ext_InstallationException(
"Unable to load ontology in '${rdfpath}' because the file is not readable."
);
}

$iterator = new FileIterator($rdfpath);
Expand Down
12 changes: 9 additions & 3 deletions common/ext/class.ExtensionUninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ public function uninstall()

// uninstall possible
if (is_null($this->extension->getManifest()->getUninstallData())) {
throw new common_Exception('Problem uninstalling extension ' . $this->extension->getId() . ' : Uninstall not supported');
throw new common_Exception(
'Problem uninstalling extension ' . $this->extension->getId() . ' : Uninstall not supported'
);
}

// installed?
if (!common_ext_ExtensionsManager::singleton()->isInstalled($this->extension->getId())) {
throw new common_Exception('Problem uninstalling extension ' . $this->extension->getId() . ' : Not installed');
throw new common_Exception(
'Problem uninstalling extension ' . $this->extension->getId() . ' : Not installed'
);
}

// check dependcies
if (helpers_ExtensionHelper::isRequired($this->extension)) {
throw new common_Exception('Problem uninstalling extension ' . $this->extension->getId() . ' : Still required');
throw new common_Exception(
'Problem uninstalling extension ' . $this->extension->getId() . ' : Still required'
);
};

common_Logger::d('uninstall script for ' . $this->extension->getId());
Expand Down
5 changes: 4 additions & 1 deletion common/ext/class.ExtensionUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ public function safeLoadService($configId)
} else {
$namespace = substr($class_name, 0, $split);
$class = substr($class_name, $split + 1);
eval('namespace ' . $namespace . '; ' . 'class ' . $class . ' extends \\oat\\oatbox\\service\\ConfigurableService {}');
eval(
'namespace ' . $namespace . '; ' . 'class ' . $class
. ' extends \\oat\\oatbox\\service\\ConfigurableService {}'
);
}
};
$serviceManager = $this->getServiceManager();
Expand Down
4 changes: 3 additions & 1 deletion common/ext/class.GenerisInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class common_ext_GenerisInstaller extends common_ext_ExtensionInstaller
public function install()
{
if ($this->extension->getId() != 'generis') {
throw new common_ext_ExtensionException('Tried to install "' . $this->extension->getId() . '" extension using the GenerisInstaller');
throw new common_ext_ExtensionException(
'Tried to install "' . $this->extension->getId() . '" extension using the GenerisInstaller'
);
}

$this->installLoadDefaultConfig();
Expand Down
13 changes: 10 additions & 3 deletions common/ext/class.UpdateExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function __invoke($params)
$report->add(new Report(Report::TYPE_ERROR, $ex->getMessage()));
break;
} catch (Exception $e) {
$this->logError('Exception during update of ' . $ext->getId() . ': ' . get_class($e) . ' "' . $e->getMessage() . '"');
$this->logError(
'Exception during update of ' . $ext->getId() . ': ' . get_class($e) . ' "' . $e->getMessage() . '"'
);
$report->setType(Report::TYPE_ERROR);
$report->setMessage('Update failed');
$report->add(new Report(Report::TYPE_ERROR, 'Exception during update of ' . $ext->getId() . '.'));
Expand All @@ -99,7 +101,10 @@ protected function updateExtension(common_ext_Extension $ext)
$installed = $this->getExtensionManager()->getInstalledVersion($ext->getId());
$codeVersion = $ext->getVersion();
if ($installed !== $codeVersion) {
$report = new Report(Report::TYPE_INFO, $ext->getName() . ' requires update from ' . $installed . ' to ' . $codeVersion);
$report = new Report(
Report::TYPE_INFO,
$ext->getName() . ' requires update from ' . $installed . ' to ' . $codeVersion
);
try {
$updater = $ext->getUpdater();
$returnedVersion = $updater->update($installed);
Expand Down Expand Up @@ -147,7 +152,9 @@ protected function updateExtension(common_ext_Extension $ext)

protected function getMissingExtensions()
{
$missingId = \helpers_ExtensionHelper::getMissingExtensionIds($this->getExtensionManager()->getInstalledExtensions());
$missingId = \helpers_ExtensionHelper::getMissingExtensionIds(
$this->getExtensionManager()->getInstalledExtensions()
);

$missingExt = [];
foreach ($missingId as $extId) {
Expand Down
3 changes: 2 additions & 1 deletion common/http/class.Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class common_http_Request
* The scheme in used (http|https) will be derived from
*
* * $_SERVER['HTTPS'] in case of a standard deployment
* * $_SERVER['HTTP_X_FORWARDED_PROTO'] or $_SERVER['HTTP_X_FORWARDED_SSL'] in case of being deployed behing a load balancer/proxy.
* * $_SERVER['HTTP_X_FORWARDED_PROTO'] or $_SERVER['HTTP_X_FORWARDED_SSL'] in case of being deployed behing a load
* balancer/proxy.
*
* If no clues about whether HTTPS is in use are found, HTTP will be the scheme of the current request.
*
Expand Down
4 changes: 3 additions & 1 deletion common/http/class.Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
class common_http_Response
{
public $httpCode;
public $headerOut; //CURLINFO_HEADER_OUT The request string sent. For this to work, add the CURLINFO_HEADER_OUT option to the handle by calling curl_setopt()
// CURLINFO_HEADER_OUT The request string sent. For this to work, add the CURLINFO_HEADER_OUT option to the handle
// by calling curl_setopt()
public $headerOut;
public $effectiveUrl; // Last effective URL
public $responseData;
}
4 changes: 3 additions & 1 deletion common/oatbox/Configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function setOptions(array $options)
if (is_object($options) && method_exists($options, 'toArray')) {
$options = $options->toArray();
} else {
throw new \common_exception_Error('Options submitted to ' . get_called_class() . ' must be an array or implement toArray');
throw new \common_exception_Error(
'Options submitted to ' . get_called_class() . ' must be an array or implement toArray'
);
}
}
$this->options = $options;
Expand Down
Loading

0 comments on commit 700d6e0

Please sign in to comment.