Permalink
Browse files

Merge pull request #7993 from creative-commoners/pulls/5.0/psr2-impro…

…vements

PSR-2 improvements
  • Loading branch information...
tractorcow committed Apr 13, 2018
2 parents 0b9e952 + 52530e7 commit 0208b2424da3c7fb3c6153797d2acf7b7ce8b633
Showing with 1,035 additions and 473 deletions.
  1. +0 −8 phpcs.xml.dist
  2. +4 −1 src/Control/Email/Email.php
  3. +10 −2 src/Control/IPUtils.php
  4. +2 −2 src/Control/NestedController.php
  5. +2 −1 src/Control/RSS/RSSFeed.php
  6. +2 −1 src/Control/RSS/RSSFeed_Entry.php
  7. +8 −3 src/Control/RequestHandler.php
  8. +3 −1 src/Core/Cache/DefaultCacheFactory.php
  9. +5 −1 src/Core/Config/Middleware/ExtensionMiddleware.php
  10. +6 −2 src/Core/CoreKernel.php
  11. +6 −10 src/Core/CustomMethods.php
  12. +3 −2 src/Core/Environment.php
  13. +5 −1 src/Core/Extensible.php
  14. +5 −1 src/Core/Manifest/ModuleResourceLoader.php
  15. +4 −1 src/Core/Startup/ErrorDirector.php
  16. +3 −1 src/Core/TempFolder.php
  17. +14 −3 src/Dev/DevelopmentAdmin.php
  18. +6 −2 src/Dev/FunctionalTest.php
  19. +50 −27 src/Dev/Install/InstallRequirements.php
  20. +5 −2 src/Dev/Install/Installer.php
  21. +2 −1 src/Dev/Install/MySQLDatabaseConfigurationHelper.php
  22. +15 −6 src/Dev/SapphireTest.php
  23. +2 −1 src/Forms/CompositeField.php
  24. +7 −2 src/Forms/ConfirmedPasswordField.php
  25. +2 −1 src/Forms/CurrencyField.php
  26. +2 −1 src/Forms/CurrencyField_Disabled.php
  27. +2 −1 src/Forms/CurrencyField_Readonly.php
  28. +4 −1 src/Forms/DatetimeField.php
  29. +2 −1 src/Forms/EmailField.php
  30. +9 −6 src/Forms/FieldList.php
  31. +2 −1 src/Forms/FormField.php
  32. +4 −2 src/Forms/FormRequestHandler.php
  33. +4 −2 src/Forms/GridField/GridField.php
  34. +11 −4 src/Forms/GridField/GridFieldAddExistingAutocompleter.php
  35. +5 −1 src/Forms/GridField/GridFieldAddNewButton.php
  36. +7 −2 src/Forms/GridField/GridFieldDeleteAction.php
  37. +33 −11 src/Forms/GridField/GridFieldDetailForm_ItemRequest.php
  38. +3 −1 src/Forms/GridField/GridFieldExportButton.php
  39. +10 −3 src/Forms/GridField/GridFieldFilterHeader.php
  40. +2 −1 src/Forms/GridField/GridFieldPageCount.php
  41. +19 −5 src/Forms/GridField/GridFieldPaginator.php
  42. +3 −1 src/Forms/GridField/GridFieldSortableHeader.php
  43. +2 −1 src/Forms/HTMLEditor/TinyMCECombinedGenerator.php
  44. +2 −2 src/Forms/HTMLEditor/TinyMCEConfig.php
  45. +1 −1 src/Forms/HiddenField.php
  46. +2 −1 src/Forms/NumericField.php
  47. +5 −5 src/Forms/SelectionGroup_Item.php
  48. +2 −1 src/ORM/ArrayList.php
  49. +1 −1 src/ORM/Connect/DBSchemaManager.php
  50. +1 −1 src/ORM/Connect/DatabaseException.php
  51. +6 −2 src/ORM/Connect/MySQLSchemaManager.php
  52. +3 −1 src/ORM/Connect/PDOConnector.php
  53. +10 −18 src/ORM/DataObject.php
  54. +18 −4 src/ORM/DataObjectSchema.php
  55. +4 −4 src/ORM/FieldType/DBBoolean.php
  56. +4 −1 src/ORM/FieldType/DBForeignKey.php
  57. +1 −1 src/ORM/Queries/SQLAssignmentRow.php
  58. +1 −1 src/ORM/Queries/SQLConditionGroup.php
  59. +1 −1 src/ORM/Queries/SQLConditionalExpression.php
  60. +1 −1 src/ORM/Queries/SQLDelete.php
  61. +1 −1 src/ORM/Queries/SQLInsert.php
  62. +1 −1 src/ORM/Queries/SQLUpdate.php
  63. +7 −5 src/ORM/Search/FulltextSearchable.php
  64. +3 −2 src/ORM/UnsavedRelationList.php
  65. +10 −3 src/ORM/ValidationResult.php
  66. +2 −1 src/Security/CMSSecurity.php
  67. +16 −12 src/Security/Group.php
  68. +4 −2 src/Security/InheritedPermissions.php
  69. +22 −7 src/Security/Member.php
  70. +2 −1 src/Security/MemberAuthenticator/CMSMemberLoginForm.php
  71. +12 −3 src/Security/MemberAuthenticator/ChangePasswordForm.php
  72. +2 −1 src/View/Parsers/HTML4Value.php
  73. +8 −5 src/View/Parsers/ShortcodeParser.php
  74. +2 −1 src/View/Parsers/URLSegmentFilter.php
  75. +4 −6 src/View/Requirements_Backend.php
  76. +2 −0 src/View/SSTemplateParser.peg
  77. +11 −9 src/View/SSTemplateParser.php
  78. +7 −2 src/View/SSViewer.php
  79. +2 −1 src/View/ThemeResourceLoader.php
  80. +3 −1 src/View/ViewableData_Debugger.php
  81. +2 −1 src/includes/constants.php
  82. +4 −1 tests/behat/travis-upload-artifacts.php
  83. +2 −1 tests/bootstrap/environment.php
  84. +3 −1 tests/bootstrap/init.php
  85. +42 −21 tests/php/Control/ControllerTest.php
  86. +112 −28 tests/php/Control/DirectorTest.php
  87. +2 −1 tests/php/Control/Email/EmailTest.php
  88. +4 −1 tests/php/Control/Email/SwiftPluginTest.php
  89. +30 −12 tests/php/Control/HTTPTest.php
  90. +3 −2 tests/php/Control/RequestHandlingTest.php
  91. +3 −3 tests/php/Control/RequestHandlingTest/AllowedController.php
  92. +2 −2 tests/php/Control/RequestHandlingTest/FormActionController.php
  93. +11 −2 tests/php/Core/ConvertTest.php
  94. +4 −2 tests/php/Core/CoreTest.php
  95. +10 −5 tests/php/Core/Injector/InjectorTest.php
  96. +4 −2 tests/php/Core/Manifest/ClassContentRemoverTest.php
  97. +1 −1 tests/php/Core/Startup/ErrorControlChainTest/ErrorControlChainTest_Chain.php
  98. +28 −7 tests/php/Core/Startup/ParameterConfirmationTokenTest.php
  99. +6 −3 tests/php/Dev/MySQLDatabaseConfigurationHelperTest.php
  100. +1 −1 tests/php/Forms/EmailFieldTest.php
  101. +3 −2 tests/php/Forms/FormTest.php
  102. +1 −1 tests/php/Forms/GridField/GridFieldAddExistingAutocompleterTest.php
  103. +14 −5 tests/php/Forms/GridField/GridFieldDeleteActionTest.php
  104. +5 −6 tests/php/Forms/GridField/GridFieldDetailFormTest.php
  105. +2 −1 tests/php/Forms/GridField/GridFieldExportButtonTest.php
  106. +8 −1 tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php
  107. +5 −8 tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest.php
  108. +9 −8 tests/php/Forms/TreeDropdownFieldTest.php
  109. +8 −4 tests/php/Forms/ValidatorTest.php
  110. +12 −3 tests/php/ORM/DBCompositeTest.php
  111. +7 −3 tests/php/ORM/DBHTMLTextTest.php
  112. +4 −1 tests/php/ORM/DBMoneyTest.php
  113. +21 −5 tests/php/ORM/DataListTest.php
  114. +32 −4 tests/php/ORM/DataObjectLazyLoadingTest.php
  115. +10 −6 tests/php/ORM/DataObjectSchemaGenerationTest.php
  116. +2 −1 tests/php/ORM/DataObjectTest.php
  117. +5 −1 tests/php/ORM/DataQueryTest.php
  118. +5 −2 tests/php/ORM/DatabaseTest.php
  119. +20 −12 tests/php/ORM/Filters/FulltextFilterTest.php
  120. +4 −2 tests/php/ORM/ManyManyListTest.php
  121. +29 −21 tests/php/ORM/SQLSelectTest.php
  122. +4 −2 tests/php/Security/MemberAuthenticatorTest.php
  123. +5 −1 tests/php/Security/MemberTest.php
  124. +8 −8 tests/php/Security/PermissionCheckboxSetFieldTest.php
  125. +6 −1 tests/php/Security/PermissionTest.php
  126. +13 −4 tests/php/Security/SecurityTest.php
  127. +9 −2 tests/php/View/Parsers/ShortcodeParserTest.php
  128. +6 −3 tests/php/View/RequirementsTest.php
  129. +11 −8 tests/php/View/SSViewerTest.php
  130. +12 −11 tests/php/View/Shortcodes/EmbedShortcodeProviderTest.php
  131. +2 −1 tests/php/i18n/i18nTest.php
View
@@ -8,14 +8,8 @@
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
- <exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
- <exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
- <exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
- <exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
- <exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
- <exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
</rule>
<rule phpcbf-only="true" ref="Squiz.Strings.ConcatenationSpacing">
@@ -28,8 +22,6 @@
<!-- include php files only -->
<arg name="extensions" value="php,lib,inc,php5"/>
- <!-- PHP-PEG generated file not intended for human consumption -->
- <exclude-pattern>*/SSTemplateParser.php$</exclude-pattern>
<exclude-pattern>*/_fakewebroot/*</exclude-pattern>
<exclude-pattern>*/fixtures/*</exclude-pattern>
</ruleset>
@@ -189,7 +189,10 @@ public static function obfuscate($email, $method = 'visible')
{
switch ($method) {
case 'direction':
- Requirements::customCSS('span.codedirection { unicode-bidi: bidi-override; direction: rtl; }', 'codedirectionCSS');
+ Requirements::customCSS(
+ 'span.codedirection { unicode-bidi: bidi-override; direction: rtl; }',
+ 'codedirectionCSS'
+ );
return '<span class="codedirection">' . strrev($email) . '</span>';
case 'visible':
View
@@ -79,7 +79,13 @@ public static function checkIP4($requestIP, $ip)
$netmask = 32;
}
- return 0 === substr_compare(sprintf('%032b', ip2long($requestIP)), sprintf('%032b', ip2long($address)), 0, $netmask);
+ $result = substr_compare(
+ sprintf('%032b', ip2long($requestIP)),
+ sprintf('%032b', ip2long($address)),
+ 0,
+ $netmask
+ );
+ return 0 === $result;
}
/**
* Compares two IPv6 addresses.
@@ -99,7 +105,9 @@ public static function checkIP4($requestIP, $ip)
public static function checkIP6($requestIP, $ip)
{
if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) {
- throw new \RuntimeException('Unable to check IPv6. Check that PHP was not compiled with option "disable-ipv6".');
+ throw new \RuntimeException(
+ 'Unable to check IPv6. Check that PHP was not compiled with option "disable-ipv6".'
+ );
}
if (false !== strpos($ip, '/')) {
@@ -4,8 +4,8 @@
/**
* Interface that is implemented by controllers that are designed to hand control over to another controller.
- * ModelAsController, which selects up a SiteTree object and passes control over to a suitable subclass of ContentController, is a good
- * example of this.
+ * ModelAsController, which selects up a SiteTree object and passes control over to a suitable subclass of
+ * ContentController, is a good example of this.
*
* Controllers that implement this interface must always return a nested controller.
*/
@@ -214,7 +214,8 @@ public function Description()
/**
* Output the feed to the browser.
*
- * TODO: Pass $response object to ->outputToBrowser() to loosen dependence on global state for easier testing/prototyping so dev can inject custom HTTPResponse instance.
+ * TODO: Pass $response object to ->outputToBrowser() to loosen dependence on global state for easier
+ * testing/prototyping so dev can inject custom HTTPResponse instance.
*
* @return DBHTMLText
*/
@@ -130,7 +130,8 @@ public function AbsoluteLink()
}
throw new BadMethodCallException(
- get_class($this->failover) . " object has neither an AbsoluteLink nor a Link method." . " Can't put a link in the RSS feed",
+ get_class($this->failover) . " object has neither an AbsoluteLink nor a Link method."
+ . " Can't put a link in the RSS feed",
E_USER_WARNING
);
}
@@ -217,7 +217,10 @@ public function handleRequest(HTTPRequest $request)
// empty rule ourselves, to prevent infinite loops. Also prevent further handling of controller
// actions which return themselves to avoid infinite loops.
$matchedRuleWasEmpty = $request->isEmptyPattern($match['rule']);
- if ($this !== $result && !$matchedRuleWasEmpty && ($result instanceof RequestHandler || $result instanceof HasRequestHandler)) {
+ if ($this !== $result
+ && !$matchedRuleWasEmpty
+ && ($result instanceof RequestHandler || $result instanceof HasRequestHandler)
+ ) {
// Expose delegated request handler
if ($result instanceof HasRequestHandler) {
$result = $result->getRequestHandler();
@@ -266,7 +269,8 @@ protected function findAction($request)
$class = static::class;
$latestParams = var_export($request->latestParams(), true);
Debug::message(
- "Rule '{$rule}' matched to action '{$action}' on {$class}. " . "Latest request params: {$latestParams}"
+ "Rule '{$rule}' matched to action '{$action}' on {$class}. "
+ . "Latest request params: {$latestParams}"
);
}
@@ -569,7 +573,8 @@ public function Link($action = null)
// no link defined by default
trigger_error(
- 'Request handler ' . static::class . ' does not have a url_segment defined. ' . 'Relying on this link may be an application error',
+ 'Request handler ' . static::class . ' does not have a url_segment defined. '
+ . 'Relying on this link may be an application error',
E_USER_WARNING
);
return null;
@@ -87,7 +87,9 @@ protected function isAPCUSupported()
static $apcuSupported = null;
if (null === $apcuSupported) {
// Need to check for CLI because Symfony won't: https://github.com/symfony/symfony/pull/25080
- $apcuSupported = Director::is_cli() ? ini_get('apc.enable_cli') && ApcuAdapter::isSupported() : ApcuAdapter::isSupported();
+ $apcuSupported = Director::is_cli()
+ ? ini_get('apc.enable_cli') && ApcuAdapter::isSupported()
+ : ApcuAdapter::isSupported();
}
return $apcuSupported;
}
@@ -56,7 +56,11 @@ protected function getExtraConfig($class, $classConfig, $excludeMiddleware)
{
// Note: 'extensions' config needs to come from it's own middleware call in case
// applied by delta middleware (e.g. Object::add_extension)
- $extensionSourceConfig = Config::inst()->get($class, null, Config::UNINHERITED | $excludeMiddleware | $this->disableFlag);
+ $extensionSourceConfig = Config::inst()->get(
+ $class,
+ null,
+ Config::UNINHERITED | $excludeMiddleware | $this->disableFlag
+ );
if (empty($extensionSourceConfig['extensions'])) {
return;
}
View
@@ -292,7 +292,8 @@ protected function detectLegacyEnvironment()
Director::absoluteBaseURL()
) .
$dv->renderParagraph(
- 'You need to replace your _ss_environment.php file with a .env file, or with environment variables.<br><br>'
+ 'You need to replace your _ss_environment.php file with a .env file, or with environment '
+ . 'variables.<br><br>'
. 'See the <a href="https://docs.silverstripe.org/en/4/getting_started/environment_management/">'
. 'Environment Management</a> docs for more information.'
) .
@@ -538,7 +539,10 @@ protected function bootErrorHandling()
if ($logger instanceof Logger) {
$logger->pushHandler(new StreamHandler($this->basePath . '/' . $errorLog, Logger::WARNING));
} else {
- user_error("SS_ERROR_LOG setting only works with Monolog, you are using another logger", E_USER_WARNING);
+ user_error(
+ "SS_ERROR_LOG setting only works with Monolog, you are using another logger",
+ E_USER_WARNING
+ );
}
}
}
View
@@ -60,10 +60,9 @@ public function __call($method, $arguments)
}
switch (true) {
- case isset($config['callback']): {
+ case isset($config['callback']):
return $config['callback']($this, $arguments);
- }
- case isset($config['property']) : {
+ case isset($config['property']):
$property = $config['property'];
$index = $config['index'];
$obj = $index !== null ?
@@ -88,21 +87,18 @@ public function __call($method, $arguments)
$obj->clearOwner();
}
}
- }
- case isset($config['wrap']): {
+ break;
+ case isset($config['wrap']):
array_unshift($arguments, $config['method']);
$wrapped = $config['wrap'];
return $this->$wrapped(...$arguments);
- }
- case isset($config['function']): {
+ case isset($config['function']):
return $config['function']($this, $arguments);
- }
- default: {
+ default:
throw new BadMethodCallException(
"Object->__call(): extra method $method is invalid on $class:"
. var_export($config, true)
);
- }
}
}
View
@@ -75,7 +75,8 @@ public static function setVariables(array $vars)
* Only increases up to the maximum defined in {@link setMemoryLimitMax()},
* and defaults to the 'memory_limit' setting in the PHP configuration.
*
- * @param string|float|int $memoryLimit A memory limit string, such as "64M". If omitted, unlimited memory will be set.
+ * @param string|float|int $memoryLimit A memory limit string, such as "64M".
+ * If omitted, unlimited memory will be set.
* @return bool true indicates a successful change, false a denied change.
*/
public static function increaseMemoryLimitTo($memoryLimit = -1)
@@ -111,7 +112,7 @@ public static function increaseMemoryLimitTo($memoryLimit = -1)
*
* @param string|float $memoryLimit Memory limit string or float value
*/
- static function setMemoryLimitMax($memoryLimit)
+ public static function setMemoryLimitMax($memoryLimit)
{
if (isset($memoryLimit) && !is_numeric($memoryLimit)) {
$memoryLimit = Convert::memstring2bytes($memoryLimit);
View
@@ -513,7 +513,11 @@ public function getExtensionInstances()
if (in_array($class, self::$unextendable_classes)) {
continue;
}
- $extensions = Config::inst()->get($class, 'extensions', Config::UNINHERITED | Config::EXCLUDE_EXTRA_SOURCES);
+ $extensions = Config::inst()->get(
+ $class,
+ 'extensions',
+ Config::UNINHERITED | Config::EXCLUDE_EXTRA_SOURCES
+ );
if ($extensions) {
foreach ($extensions as $extension) {
@@ -92,6 +92,7 @@ public static function get_template_global_variables()
*
* @param string $resource
* @return ModuleResource|string The resource, or input string if not a module resource
+ * @throws InvalidArgumentException
*/
public function resolveResource($resource)
{
@@ -103,7 +104,10 @@ public function resolveResource($resource)
$resource = $matches['resource'];
$moduleObj = ModuleLoader::getModule($module);
if (!$moduleObj) {
- throw new InvalidArgumentException("Can't find module '$module', the composer.json file may be missing from the modules installation directory");
+ throw new InvalidArgumentException(
+ "Can't find module '$module', the composer.json file may be missing from the modules "
+ . "installation directory"
+ );
}
$resourceObj = $moduleObj->getResource($resource);
@@ -31,7 +31,10 @@ public function handleRequestWithToken(HTTPRequest $request, ParameterConfirmati
// Next, check if we're in dev mode, or the database doesn't have any security data, or we are admin
$reload = function (HTTPRequest $request) use ($token, $kernel) {
- if ($kernel->getEnvironment() === Kernel::DEV || !Security::database_is_ready() || Permission::check('ADMIN')) {
+ if ($kernel->getEnvironment() === Kernel::DEV
+ || !Security::database_is_ready()
+ || Permission::check('ADMIN')
+ ) {
return $token->reloadWithToken();
}
return null;
View
@@ -108,7 +108,9 @@ protected static function getTempParentFolder($base)
if (!$worked) {
throw new Exception(
- 'Permission problem gaining access to a temp folder. ' . 'Please create a folder named silverstripe-cache in the base folder ' . 'of the installation and ensure it has the correct permissions'
+ 'Permission problem gaining access to a temp folder. '
+ . 'Please create a folder named silverstripe-cache in the base folder '
+ . 'of the installation and ensure it has the correct permissions'
);
}
@@ -2,12 +2,14 @@
namespace SilverStripe\Dev;
+use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\Controller;
+use SilverStripe\Security\RandomGenerator;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\DatabaseAdmin;
use SilverStripe\Security\Permission;
@@ -113,6 +115,12 @@ public function index()
}
}
+ /**
+ * @param HTTPRequest $request
+ * @return Controller
+ * @throws Exception
+ * @throws HTTPResponse_Exception
+ */
public function runRegisteredController(HTTPRequest $request)
{
$controllerClass = null;
@@ -129,7 +137,8 @@ public function runRegisteredController(HTTPRequest $request)
$msg = 'Error: no controller registered in ' . __CLASS__ . ' for: ' . $request->param('Action');
if (Director::is_cli()) {
- // in CLI we cant use httpError because of a bug with stuff being in the output already, see DevAdminControllerTest
+ // in CLI we cant use httpError because of a bug with stuff being in the output already,
+ // see DevAdminControllerTest
throw new Exception($msg);
} else {
$this->httpError(500, $msg);
@@ -207,10 +216,12 @@ public function buildDefaults()
/**
* Generate a secure token which can be used as a crypto key.
* Returns the token and suggests PHP configuration to set it.
+ *
+ * @return HTTPResponse
*/
public function generatesecuretoken()
{
- $generator = Injector::inst()->create('SilverStripe\\Security\\RandomGenerator');
+ $generator = Injector::inst()->create(RandomGenerator::class);
$token = $generator->randomToken('sha1');
$body = <<<TXT
Generated new token. Please add the following code to your YAML configuration:
@@ -219,7 +230,7 @@ public function generatesecuretoken()
token: $token
TXT;
- $response = new HTTPResponse($body);
+ $response = HTTPResponse::create($body);
return $response->addHeader('Content-Type', 'text/plain');
}
@@ -155,8 +155,12 @@ protected function withBaseFolder(string $folder, callable $callback)
* @param array $cookies
* @return HTTPResponse
*/
- public function get(string $url, Session $session = null, array $headers = null, array $cookies = null) : HTTPResponse
- {
+ public function get(
+ string $url,
+ Session $session = null,
+ array $headers = null,
+ array $cookies = null
+ ) : HTTPResponse {
$this->cssParser = null;
$response = $this->mainSession->get($url, $session, $headers, $cookies);
if ($this->autoFollowRedirection && is_object($response) && $response->getHeader('Location')) {
Oops, something went wrong.

0 comments on commit 0208b24

Please sign in to comment.