Skip to content

Commit

Permalink
TASK: Code cleanup
Browse files Browse the repository at this point in the history
Import namespaces and apply code style changes suggested by PHP Inspections Phpstorm Plugin
  • Loading branch information
simonschaufi committed Jan 8, 2020
1 parent 8611798 commit 4a48907
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 60 deletions.
7 changes: 4 additions & 3 deletions Classes/Condition/DatabaseConnectionCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Doctrine\DBAL\DriverManager;
use Neos\Flow\Configuration\ConfigurationManager;

/**
* Condition that checks whether connection to the configured database can be established
Expand All @@ -25,9 +26,9 @@ class DatabaseConnectionCondition extends AbstractCondition
*/
public function isMet()
{
$settings = $this->configurationManager->getConfiguration(\Neos\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow');
$settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow');
try {
\Doctrine\DBAL\DriverManager::getConnection($settings['persistence']['backendOptions'])->connect();
DriverManager::getConnection($settings['persistence']['backendOptions'])->connect();
} catch (\PDOException $exception) {
return false;
}
Expand Down
6 changes: 1 addition & 5 deletions Classes/Condition/PdoDriverCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class PdoDriverCondition extends AbstractCondition
*/
public function isMet()
{
if (defined('PDO::ATTR_DRIVER_NAME') === false || \PDO::getAvailableDrivers() === []) {
return false;
}

return true;
return !(defined('PDO::ATTR_DRIVER_NAME') === false || \PDO::getAvailableDrivers() === []);
}
}
8 changes: 5 additions & 3 deletions Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Error\Messages\Message;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Security\Exception\AuthenticationRequiredException;
use Neos\Utility\Files;

/**
* @Flow\Scope("singleton")
*/
class LoginController extends \Neos\Flow\Mvc\Controller\ActionController
class LoginController extends ActionController
{
/**
* @var string
Expand Down Expand Up @@ -99,7 +101,7 @@ public function authenticateAction($step)
unlink($this->settings['initialPasswordFile']);
}
$this->redirect('index', 'Setup', null, ['step' => $step]);
} catch (\Neos\Flow\Security\Exception\AuthenticationRequiredException $exception) {
} catch (AuthenticationRequiredException $exception) {
$this->addFlashMessage('Sorry, you were not able to authenticate.', 'Authentication error', Message::SEVERITY_ERROR);
$this->redirect('login', null, null, ['step' => $step]);
}
Expand Down
23 changes: 14 additions & 9 deletions Classes/Controller/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
* source code.
*/

use Neos\Error\Messages\Message;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Form\Core\Model\FinisherContext;
use Neos\Setup\Step\StepInterface;

/**
* @Flow\Scope("singleton")
*/
class SetupController extends \Neos\Flow\Mvc\Controller\ActionController
class SetupController extends ActionController
{
/**
* The authentication manager
Expand Down Expand Up @@ -54,7 +59,7 @@ class SetupController extends \Neos\Flow\Mvc\Controller\ActionController
*/
protected function initializeAction()
{
$this->distributionSettings = $this->configurationSource->load(FLOW_PATH_CONFIGURATION . \Neos\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
$this->distributionSettings = $this->configurationSource->load(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
}

/**
Expand All @@ -68,7 +73,7 @@ public function indexAction($step = 0)
$this->checkRequestedStepIndex();
$currentStep = $this->instantiateCurrentStep();
$controller = $this;
$callback = function (\Neos\Form\Core\Model\FinisherContext $finisherContext) use ($controller, $currentStep) {
$callback = function (FinisherContext $finisherContext) use ($controller, $currentStep) {
$controller->postProcessStep($finisherContext->getFormValues(), $currentStep);
};
$formDefinition = $currentStep->getFormDefinition($callback);
Expand All @@ -89,7 +94,7 @@ public function indexAction($step = 0)
try {
$renderedForm = $form->render();
} catch (\Neos\Setup\Exception $exception) {
$this->addFlashMessage($exception->getMessage(), 'Exception while executing setup step', \Neos\Error\Messages\Message::SEVERITY_ERROR);
$this->addFlashMessage($exception->getMessage(), 'Exception while executing setup step', Message::SEVERITY_ERROR);
$this->redirect('index', null, null, ['step' => $this->currentStepIndex]);
}
$this->view->assignMultiple([
Expand Down Expand Up @@ -117,9 +122,9 @@ protected function checkRequestedStepIndex()
if ($this->currentStepIndex === 0) {
throw new \Neos\Setup\Exception('Not all requirements are met for the first setup step, aborting setup', 1332169088);
}
$this->addFlashMessage('Not all requirements are met for step "%s"', '', \Neos\Error\Messages\Message::SEVERITY_ERROR, [$stepOrder[$this->currentStepIndex]]);
$this->addFlashMessage('Not all requirements are met for step "%s"', '', Message::SEVERITY_ERROR, [$stepOrder[$this->currentStepIndex]]);
$this->redirect('index', null, null, ['step' => $this->currentStepIndex - 1]);
};
}
}

/**
Expand All @@ -134,7 +139,7 @@ protected function instantiateCurrentStep()
throw new \Neos\Setup\Exception(sprintf('No className specified for setup step "%s", setup can\'t be invoked', $currentStepIdentifier), 1332169398);
}
$currentStep = new $currentStepConfiguration['className']();
if (!$currentStep instanceof \Neos\Setup\Step\StepInterface) {
if (!$currentStep instanceof StepInterface) {
throw new \Neos\Setup\Exception(sprintf('ClassName %s of setup step "%s" does not implement StepInterface, setup can\'t be invoked', $currentStepConfiguration['className'], $currentStepIdentifier), 1332169576);
}
if (isset($currentStepConfiguration['options'])) {
Expand Down Expand Up @@ -183,12 +188,12 @@ protected function checkRequiredConditions($stepIdentifier)
* @param \Neos\Setup\Step\StepInterface $currentStep
* @return void
*/
public function postProcessStep(array $formValues, \Neos\Setup\Step\StepInterface $currentStep)
public function postProcessStep(array $formValues, StepInterface $currentStep)
{
try {
$currentStep->postProcessFormValues($formValues);
} catch (\Neos\Setup\Exception $exception) {
$this->addFlashMessage($exception->getMessage(), 'Exception while executing setup step', \Neos\Error\Messages\Message::SEVERITY_ERROR);
$this->addFlashMessage($exception->getMessage(), 'Exception while executing setup step', Message::SEVERITY_ERROR);
$this->redirect('index', null, null, ['step' => $this->currentStepIndex]);
}
$this->redirect('index', null, null, ['step' => $this->currentStepIndex + 1]);
Expand Down
7 changes: 4 additions & 3 deletions Classes/Core/BasicRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Error\Messages\Error;
use Neos\Flow\Annotations as Flow;
use Neos\Utility\Files;

/**
* This class checks the basic requirements and returns an error object in case
Expand Down Expand Up @@ -154,9 +155,9 @@ protected function checkFilePermissions()
{
foreach ($this->requiredWritableFolders as $folder) {
$folderPath = FLOW_PATH_ROOT . $folder;
if (!is_dir($folderPath) && !\Neos\Utility\Files::is_link($folderPath)) {
if (!is_dir($folderPath) && !Files::is_link($folderPath)) {
try {
\Neos\Utility\Files::createDirectoryRecursively($folderPath);
Files::createDirectoryRecursively($folderPath);
} catch (\Neos\Flow\Utility\Exception $exception) {
return new Error('Unable to create folder "%s". Check your file permissions (did you use flow:core:setfilepermissions?).', 1330363887, [$folderPath]);
}
Expand Down
10 changes: 7 additions & 3 deletions Classes/Core/ConfigureRoutingComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Configuration\Source\YamlSource;
use Neos\Flow\Http\Component\ComponentContext;
use Neos\Flow\Http\Component\ComponentInterface;
use Neos\Flow\Mvc\Routing\Router;
use Neos\Flow\Mvc\Routing\RoutingComponent;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Flow\Package\PackageManager;

Expand Down Expand Up @@ -70,9 +72,11 @@ public function __construct(array $options = [])
*/
public function handle(ComponentContext $componentContext)
{
$configurationSource = $this->objectManager->get(\Neos\Flow\Configuration\Source\YamlSource::class);
$routesConfiguration = $configurationSource->load($this->packageManager->getPackage('Neos.Setup')->getConfigurationPath() . ConfigurationManager::CONFIGURATION_TYPE_ROUTES);
$configurationSource = $this->objectManager->get(YamlSource::class);
$routesConfiguration = $configurationSource->load(
$this->packageManager->getPackage('Neos.Setup')->getConfigurationPath() . ConfigurationManager::CONFIGURATION_TYPE_ROUTES
);
$this->router->setRoutesConfiguration($routesConfiguration);
$componentContext->setParameter(\Neos\Flow\Mvc\Routing\RoutingComponent::class, 'skipRouterInitialization', true);
$componentContext->setParameter(RoutingComponent::class, 'skipRouterInitialization', true);
}
}
5 changes: 3 additions & 2 deletions Classes/Core/MessageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Error\Messages\Message;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\PackageManager;

/**
Expand All @@ -37,7 +38,7 @@ class MessageRenderer
*
* @param \Neos\Flow\Core\Bootstrap $bootstrap
*/
public function __construct(\Neos\Flow\Core\Bootstrap $bootstrap)
public function __construct(Bootstrap $bootstrap)
{
$this->bootstrap = $bootstrap;
}
Expand Down
31 changes: 16 additions & 15 deletions Classes/Core/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use GuzzleHttp\Psr7\ServerRequest;
use Neos\Error\Messages\Warning;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Configuration\Source\YamlSource;
Expand All @@ -37,7 +38,11 @@ class RequestHandler extends FlowRequestHandler
*/
public function canHandleRequest()
{
return (PHP_SAPI !== 'cli' && ((strlen($_SERVER['REQUEST_URI']) === 6 && $_SERVER['REQUEST_URI'] === '/setup') || in_array(substr($_SERVER['REQUEST_URI'], 0, 7), ['/setup/', '/setup?'])));
return (PHP_SAPI !== 'cli'
&& (
(strlen($_SERVER['REQUEST_URI']) === 6 && $_SERVER['REQUEST_URI'] === '/setup')
|| in_array(substr($_SERVER['REQUEST_URI'], 0, 7), ['/setup/', '/setup?'])
));
}

/**
Expand Down Expand Up @@ -148,7 +153,7 @@ protected function checkAndSetPhpBinaryIfNeeded()
$defaultPhpBinaryPathAndFilename = str_replace('\\', '/', $defaultPhpBinaryPathAndFilename) . '.exe';
}
if ($phpBinaryPathAndFilename !== $defaultPhpBinaryPathAndFilename) {
$distributionSettings = \Neos\Utility\Arrays::setValueByPath($distributionSettings, 'Neos.Flow.core.phpBinaryPathAndFilename', $phpBinaryPathAndFilename);
$distributionSettings = Arrays::setValueByPath($distributionSettings, 'Neos.Flow.core.phpBinaryPathAndFilename', $phpBinaryPathAndFilename);
$configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $distributionSettings);
}
}
Expand Down Expand Up @@ -189,14 +194,14 @@ protected function checkPhpBinary($phpBinaryPathAndFilename)
}
if ($phpVersion === null) {
return new Error('The specified path to your PHP binary (see Configuration/Settings.yaml) is incorrect: not found at "%s"', 1341839376, [$phpBinaryPathAndFilename], 'Environment requirements not fulfilled');
} else {
$phpMinorVersionMatch = array_slice(explode('.', $phpVersion), 0, 2) === array_slice(explode('.', PHP_VERSION), 0, 2);
if ($phpMinorVersionMatch) {
return new \Neos\Error\Messages\Warning('The specified path to your PHP binary (see Configuration/Settings.yaml) points to a PHP binary with the version "%s". This is not the exact same version as is currently running ("%s").', 1416913501, [$phpVersion, PHP_VERSION], 'Possible PHP version mismatch');
} else {
return new Error('The specified path to your PHP binary (see Configuration/Settings.yaml) points to a PHP binary with the version "%s". This is not compatible to the version that is currently running ("%s").', 1341839377, [$phpVersion, PHP_VERSION], 'Environment requirements not fulfilled');
}
}

$phpMinorVersionMatch = array_slice(explode('.', $phpVersion), 0, 2) === array_slice(explode('.', PHP_VERSION), 0, 2);
if ($phpMinorVersionMatch) {
return new Warning('The specified path to your PHP binary (see Configuration/Settings.yaml) points to a PHP binary with the version "%s". This is not the exact same version as is currently running ("%s").', 1416913501, [$phpVersion, PHP_VERSION], 'Possible PHP version mismatch');
}

return new Error('The specified path to your PHP binary (see Configuration/Settings.yaml) points to a PHP binary with the version "%s". This is not compatible to the version that is currently running ("%s").', 1341839377, [$phpVersion, PHP_VERSION], 'Environment requirements not fulfilled');
}

/**
Expand All @@ -222,7 +227,7 @@ protected function detectPhpBinaryPathAndFilename()
$lastCheckMessage = null;
foreach ($environmentPaths as $path) {
$path = rtrim(str_replace('\\', '/', $path), '/');
if (strlen($path) === 0) {
if ($path === '') {
continue;
}
$phpBinaryPathAndFilename = $path . '/php' . (DIRECTORY_SEPARATOR !== '/' ? '.exe' : '');
Expand Down Expand Up @@ -255,10 +260,6 @@ protected function phpBinaryExistsAndIsExecutableFile($phpBinaryPathAndFilename)
}

exec($command, $outputLines, $exitCode);
if ($exitCode === 0) {
return true;
}

return false;
return $exitCode === 0;
}
}
6 changes: 4 additions & 2 deletions Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Setup\Core\RequestHandler;

/**
* Package base class of the Neos.Setup package.
Expand All @@ -27,8 +29,8 @@ class Package extends BasePackage
* @param \Neos\Flow\Core\Bootstrap $bootstrap The current bootstrap
* @return void
*/
public function boot(\Neos\Flow\Core\Bootstrap $bootstrap)
public function boot(Bootstrap $bootstrap)
{
$bootstrap->registerRequestHandler(new \Neos\Setup\Core\RequestHandler($bootstrap));
$bootstrap->registerRequestHandler(new RequestHandler($bootstrap));
}
}
16 changes: 10 additions & 6 deletions Classes/Step/AbstractStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Form\Core\Model\FormDefinition;
use Neos\Form\Exception\PresetNotFoundException;
use Neos\Form\Finishers\ClosureFinisher;
use Neos\Utility\Arrays;

/**
* @Flow\Scope("singleton")
*/
abstract class AbstractStep implements \Neos\Setup\Step\StepInterface
abstract class AbstractStep implements StepInterface
{
/**
* @var boolean
Expand Down Expand Up @@ -58,7 +62,7 @@ abstract class AbstractStep implements \Neos\Setup\Step\StepInterface
*/
public function initializeObject()
{
$this->formSettings = $this->configurationManager->getConfiguration(\Neos\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Form');
$this->formSettings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Form');
}

/**
Expand Down Expand Up @@ -97,13 +101,13 @@ public function setDistributionSettings(array $distributionSettings)
public function getPresetConfiguration($presetName)
{
if (!isset($this->formSettings['presets'][$presetName])) {
throw new \Neos\Form\Exception\PresetNotFoundException(sprintf('The Preset "%s" was not found underneath Neos: Form: presets.', $presetName), 1332170104);
throw new PresetNotFoundException(sprintf('The Preset "%s" was not found underneath Neos: Form: presets.', $presetName), 1332170104);
}
$preset = $this->formSettings['presets'][$presetName];
if (isset($preset['parentPreset'])) {
$parentPreset = $this->getPresetConfiguration($preset['parentPreset']);
unset($preset['parentPreset']);
$preset = \Neos\Utility\Arrays::arrayMergeRecursiveOverrule($parentPreset, $preset);
$preset = Arrays::arrayMergeRecursiveOverrule($parentPreset, $preset);
}

return $preset;
Expand All @@ -124,7 +128,7 @@ final public function getFormDefinition(\Closure $callback)
$formDefinition = new FormDefinition($formIdentifier, $formConfiguration);
$this->buildForm($formDefinition);

$closureFinisher = new \Neos\Form\Finishers\ClosureFinisher();
$closureFinisher = new ClosureFinisher();
$closureFinisher->setOption('closure', $callback);
$formDefinition->addFinisher($closureFinisher);

Expand All @@ -137,7 +141,7 @@ final public function getFormDefinition(\Closure $callback)
* @return void
* @api
*/
abstract protected function buildForm(\Neos\Form\Core\Model\FormDefinition $formDefinition);
abstract protected function buildForm(FormDefinition $formDefinition);

/**
* This method is called when the form of this step has been submitted
Expand Down
2 changes: 1 addition & 1 deletion Classes/Step/DatabaseStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* @Flow\Scope("singleton")
*/
class DatabaseStep extends \Neos\Setup\Step\AbstractStep
class DatabaseStep extends AbstractStep
{
/**
* @var \Neos\Flow\Configuration\Source\YamlSource
Expand Down
Loading

0 comments on commit 4a48907

Please sign in to comment.