Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce static analysis #9035

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"ext-xml": "*"
},
"require-dev": {
"phpstan/phpstan-shim": "^0.11.8",
"phpunit/phpunit": "^5.7",
"silverstripe/versioned": "^1"
},
Expand Down
29 changes: 29 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
parameters:
level: 0
paths:
- %currentWorkingDirectory%/src/
excludes_analyse:
# PHPStan bug?? https://github.com/phpstan/phpstan/issues/2171
- %currentWorkingDirectory%/src/View/SSTemplateParser.php
# tidy ext.
- %currentWorkingDirectory%/src/View/Parsers/TidyHTMLCleaner.php
- %currentWorkingDirectory%/src/Dev/CSSContentParser.php
# ezyang/htmlpurifier
- %currentWorkingDirectory%/src/View/Parsers/PurifierHTMLCleaner.php
# Memcached ext.
- %currentWorkingDirectory%/src/Core/Cache/MemcachedCacheFactory.php
# symfony/console
- %currentWorkingDirectory%/src/Dev/Upgrade/UpgradeBootstrap.php
# Previous version
- %currentWorkingDirectory%/src/Dev/Tasks/MigrateFileTask.php
- %currentWorkingDirectory%/src/Forms/GridField/GridFieldVersionedState.php
# npm package tinymce_compressor
- %currentWorkingDirectory%/src/Forms/HTMLEditor/TinyMCEGZIPGenerator.php
autoload_files:
- %currentWorkingDirectory%/thirdparty/php-peg/Parser.php
- %currentWorkingDirectory%/thirdparty/difflib/difflib.php
- %currentWorkingDirectory%/thirdparty/simpletest/selector.php
- %currentWorkingDirectory%/thirdparty/simpletest/page.php
ignoreErrors:
# # Where is TransactionalDBConnector?
# - '#^Class SilverStripe\\ORM\\Connect\\TransactionalDBConnector not found\.$#'
2 changes: 1 addition & 1 deletion src/Control/IPUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
namespace SilverStripe\Control\Util;
szepeviktor marked this conversation as resolved.
Show resolved Hide resolved
namespace SilverStripe\Control;

/**
* Http utility functions.
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Middleware/TrustedProxyMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\Control\Middleware;

use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Util\IPUtils;
use SilverStripe\Control\IPUtils;

/**
* This middleware will rewrite headers that provide IP and host details from an upstream proxy.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ClassManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public function regenerate($includeTests)
'name_regex' => '/^[^_].*\\.php$/',
'ignore_files' => array('index.php', 'cli-script.php'),
'ignore_tests' => !$includeTests,
'file_callback' => function ($basename, $pathname, $depth) use ($includeTests, $finder) {
'file_callback' => function ($basename, $pathname, $depth) use ($includeTests) {
$this->handleFile($basename, $pathname, $includeTests);
},
));
Expand Down
8 changes: 0 additions & 8 deletions src/Dev/DebugView.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class DebugView
'title' => 'Alert',
'class' => 'error'
),
2 => array(
'title' => 'Critical',
'class' => 'error'
),
3 => array(
'title' => 'Error',
'class' => 'error'
Expand Down Expand Up @@ -86,10 +82,6 @@ class DebugView
'title' => 'User Deprecated',
'class' => 'notice'
),
E_CORE_ERROR => array(
Copy link
Contributor Author

@szepeviktor szepeviktor Jun 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 are doubles.

'title' => 'Core Error',
'class' => 'error'
),
E_WARNING => array(
'title' => 'Warning',
'class' => 'warning'
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/Install/InstallRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function check($originalIni)
// in addition to the temp folder being available, check it is writable
$this->requireWriteable($tempFolder, array(
"File permissions",
sprintf("Is the temporary directory writeable?", $tempFolder),
sprintf("Is the temporary directory (%s) writeable?", $tempFolder),
null
), true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/ConfirmedPasswordField.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ConfirmedPasswordField extends FormField
* @param string $name
* @param string $title
* @param mixed $value
* @param Form $form
* @param Form $form Ignored for ConfirmedPasswordField.
* @param boolean $showOnClick
* @param string $titleConfirmField Alternate title (not localizeable)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public function extraClass()
//
// CSS class needs to be different from the one rendered through {@link FieldHolder()}.
if ($this->getMessage()) {
$classes[] .= 'holder-' . $this->getMessageType();
$classes[] = 'holder-' . $this->getMessageType();
}

return implode(' ', $classes);
Expand Down
2 changes: 2 additions & 0 deletions src/Forms/GridField/GridField_ActionMenuLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SilverStripe\Forms\GridField;

use SilverStripe\ORM\DataObject;

/**
* Allows GridField_ActionMenuItem to act as a link
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/NullableField.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setName($name)
public function debug()
{
$result = sprintf(
'%s (%s: $s : <span style="color: red">%s</span>) = ',
'%s (%s: %s : <span style="color: red">%s</span>) = ',
static::class,
$this->name,
$this->title,
Expand Down
1 change: 1 addition & 0 deletions src/ORM/Connect/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\ArrayList;
Expand Down
10 changes: 5 additions & 5 deletions src/ORM/Connect/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ public function alterTable(

if ($newFields) {
foreach ($newFields as $k => $v) {
$alterList[] .= "ADD \"$k\" $v";
$alterList[] = "ADD \"$k\" $v";
}
}
if ($newIndexes) {
foreach ($newIndexes as $k => $v) {
$alterList[] .= "ADD " . $this->getIndexSqlDefinition($k, $v);
$alterList[] = "ADD " . $this->getIndexSqlDefinition($k, $v);
}
}
if ($alteredFields) {
foreach ($alteredFields as $k => $v) {
$alterList[] .= "CHANGE \"$k\" \"$k\" $v";
$alterList[] = "CHANGE \"$k\" \"$k\" $v";
}
}
if ($alteredIndexes) {
foreach ($alteredIndexes as $k => $v) {
$alterList[] .= "DROP INDEX \"$k\"";
$alterList[] .= "ADD " . $this->getIndexSqlDefinition($k, $v);
$alterList[] = "DROP INDEX \"$k\"";
$alterList[] = "ADD " . $this->getIndexSqlDefinition($k, $v);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ORM/DatabaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function doBuild($quiet = false, $populate = true, $testMode = false)
try {
$count = DB::query("SELECT COUNT(*) FROM \"$tableName\"")->value();
$countSuffix = " ($count records)";
} catch (Exception $e) {
} catch (\Exception $e) {
$countSuffix = " (error getting record count)";
}
} else {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ORM/FieldType/DBLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getLongName()
public function getNativeName()
{
$locale = $this->value;
return i18n::with_locale($locale, function () use ($locale) {
return i18n::with_locale($locale, function () {
return $this->getShortName();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/View/Parsers/ShortcodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function set_active($identifier)
* - An associative array of extra information about the shortcode being parsed.
*
* @param string $shortcode The shortcode tag to map to the callback - normally in lowercase_underscore format.
* @param callback $callback The callback to replace the shortcode with.
* @param callable $callback The callback to replace the shortcode with.
* @return $this
*/
public function register($shortcode, $callback)
Expand Down
2 changes: 1 addition & 1 deletion src/View/ThemeManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getCacheKey($includeTests = false)
}

/**
* @return \string[]
* @return string[]
*/
public function getThemes()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Control/IPUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Util\IPUtils;
use SilverStripe\Control\IPUtils;

class IPUtilsTest extends SapphireTest
{
Expand Down