Skip to content
Snippets Groups Projects
Commit b1d74476 authored by Ted Bowman's avatar Ted Bowman Committed by Adam G-H
Browse files

Issue #3342120 by Wim Leers, yash.rode, tedbow, phenaproxima: Fix PHPStan...

Issue #3342120 by Wim Leers, yash.rode, tedbow, phenaproxima: Fix PHPStan violations (happened because PHPStan code checks stopped running…)
parent 79b7c59a
No related branches found
No related tags found
No related merge requests found
Showing
with 40 additions and 27 deletions
...@@ -96,8 +96,8 @@ final class BatchProcessor { ...@@ -96,8 +96,8 @@ final class BatchProcessor {
* @see \Drupal\automatic_updates\Updater::stage() * @see \Drupal\automatic_updates\Updater::stage()
*/ */
public static function stage(array &$context): void { public static function stage(array &$context): void {
$stage_id = \Drupal::service('session')->get(static::STAGE_ID_SESSION_KEY);
try { try {
$stage_id = \Drupal::service('session')->get(static::STAGE_ID_SESSION_KEY);
static::getUpdater()->claim($stage_id)->stage(); static::getUpdater()->claim($stage_id)->stage();
} }
catch (\Throwable $e) { catch (\Throwable $e) {
......
...@@ -164,7 +164,7 @@ final class UpdaterForm extends UpdateFormBase { ...@@ -164,7 +164,7 @@ final class UpdaterForm extends UpdateFormBase {
$results = []; $results = [];
} }
else { else {
$results = $this->runStatusCheck($this->extensionUpdater, $this->eventDispatcher, TRUE); $results = $this->runStatusCheck($this->extensionUpdater, $this->eventDispatcher);
} }
$this->displayResults($results, $this->renderer); $this->displayResults($results, $this->renderer);
$security_level = ValidationResult::getOverallSeverity($results); $security_level = ValidationResult::getOverallSeverity($results);
......
...@@ -5,6 +5,7 @@ declare(strict_types = 1); ...@@ -5,6 +5,7 @@ declare(strict_types = 1);
namespace Drupal\Tests\automatic_updates_extensions\Traits; namespace Drupal\Tests\automatic_updates_extensions\Traits;
use Behat\Mink\WebAssert; use Behat\Mink\WebAssert;
use Drupal\Tests\BrowserTestBase;
/** /**
* Common methods for testing the update form. * Common methods for testing the update form.
...@@ -41,6 +42,7 @@ trait FormTestTrait { ...@@ -41,6 +42,7 @@ trait FormTestTrait {
* The no of rows in table. * The no of rows in table.
*/ */
protected function assertUpdatesCount(int $expected_update_count): void { protected function assertUpdatesCount(int $expected_update_count): void {
assert($this instanceof BrowserTestBase);
$this->assertSession()->elementsCount('css', '.update-recommended tbody tr', $expected_update_count); $this->assertSession()->elementsCount('css', '.update-recommended tbody tr', $expected_update_count);
} }
......
...@@ -214,7 +214,7 @@ class FixtureManipulator { ...@@ -214,7 +214,7 @@ class FixtureManipulator {
$data['dev-package-names'] = array_values($data['dev-package-names']); $data['dev-package-names'] = array_values($data['dev-package-names']);
} }
// Add the package back to the list, if we have data for it. // Add the package back to the list, if we have data for it.
if (isset($package)) { if (isset($install_json_package)) {
$data['packages'][] = $install_json_package; $data['packages'][] = $install_json_package;
if ($is_dev_requirement || !empty($is_existing_dev_package)) { if ($is_dev_requirement || !empty($is_existing_dev_package)) {
......
...@@ -276,10 +276,7 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { ...@@ -276,10 +276,7 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
// This validator will persist through container rebuilds. // This validator will persist through container rebuilds.
// @see ::register() // @see ::register()
$validator = new TestDiskSpaceValidator( $validator = new TestDiskSpaceValidator($path_locator);
$path_locator,
$this->container->get('string_translation')
);
// By default, the validator should report that the root, vendor, and // By default, the validator should report that the root, vendor, and
// temporary directories have basically infinite free space. // temporary directories have basically infinite free space.
$validator->freeSpace = [ $validator->freeSpace = [
......
...@@ -267,6 +267,7 @@ class StageOwnershipTest extends PackageManagerKernelTestBase { ...@@ -267,6 +267,7 @@ class StageOwnershipTest extends PackageManagerKernelTestBase {
// don't wan't to do that in this test, since we're specifically testing // don't wan't to do that in this test, since we're specifically testing
// what happens when we try to delete a stage directory with // what happens when we try to delete a stage directory with
// write-protected files. // write-protected files.
return TRUE;
} }
/** /**
......
...@@ -17,6 +17,7 @@ use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface; ...@@ -17,6 +17,7 @@ use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface;
use PhpTuf\ComposerStager\Domain\Value\PathList\PathListInterface; use PhpTuf\ComposerStager\Domain\Value\PathList\PathListInterface;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
/** /**
* @covers \Drupal\package_manager\Validator\SymlinkValidator * @covers \Drupal\package_manager\Validator\SymlinkValidator
...@@ -105,6 +106,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase { ...@@ -105,6 +106,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
// Ensure that the Composer Stager's symlink precondition is invoked. // Ensure that the Composer Stager's symlink precondition is invoked.
$this->precondition->assertIsFulfilled(...$arguments) $this->precondition->assertIsFulfilled(...$arguments)
->will(function (array $arguments) use ($symlinks_exist): void { ->will(function (array $arguments) use ($symlinks_exist): void {
assert($this instanceof ObjectProphecy);
// Ensure that 'ignore/me' is present in ignored paths. // Ensure that 'ignore/me' is present in ignored paths.
Assert::assertContains('ignore/me', $arguments[2]->getAll()); Assert::assertContains('ignore/me', $arguments[2]->getAll());
......
...@@ -5,8 +5,10 @@ declare(strict_types = 1); ...@@ -5,8 +5,10 @@ declare(strict_types = 1);
namespace Drupal\Tests\package_manager\Traits; namespace Drupal\Tests\package_manager\Traits;
use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\KernelTests\KernelTestBase;
use Drupal\package_manager\PathLocator; use Drupal\package_manager\PathLocator;
use Drupal\package_manager\ValidationResult; use Drupal\package_manager\ValidationResult;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
/** /**
...@@ -64,6 +66,8 @@ trait ValidationTestTrait { ...@@ -64,6 +66,8 @@ trait ValidationTestTrait {
*/ */
protected function resolvePlaceholdersInArrayValuesWithRealPaths(array $subject, ?PathLocator $path_locator = NULL, ?string $stage_dir = NULL): array { protected function resolvePlaceholdersInArrayValuesWithRealPaths(array $subject, ?PathLocator $path_locator = NULL, ?string $stage_dir = NULL): array {
if (!$path_locator) { if (!$path_locator) {
// Only kernel and browser tests have $this->container.
assert($this instanceof KernelTestBase || $this instanceof BrowserTestBase);
$path_locator = $this->container->get('package_manager.path_locator'); $path_locator = $this->container->get('package_manager.path_locator');
} }
$subject = str_replace( $subject = str_replace(
...@@ -97,6 +101,7 @@ trait ValidationTestTrait { ...@@ -97,6 +101,7 @@ trait ValidationTestTrait {
protected function getValidationResultsAsArray(array $results): array { protected function getValidationResultsAsArray(array $results): array {
$string_translation_stub = NULL; $string_translation_stub = NULL;
if (is_a(get_called_class(), UnitTestCase::class, TRUE)) { if (is_a(get_called_class(), UnitTestCase::class, TRUE)) {
assert($this instanceof UnitTestCase);
$string_translation_stub = $this->getStringTranslationStub(); $string_translation_stub = $this->getStringTranslationStub();
} }
return array_values(array_map(static function (ValidationResult $result) use ($string_translation_stub) { return array_values(array_map(static function (ValidationResult $result) use ($string_translation_stub) {
......
includes:
- %rootDir%/../../../core/phpstan.neon.dist
parameters:
ignoreErrors:
# Drupal core's PHPStan config file ignores the non-anonymous variant of this.
- "#^Anonymous class extends @internal class#"
# Drupal core needs to ignore more things than we need to!
reportUnmatchedIgnoredErrors: false
...@@ -95,10 +95,9 @@ print_title "[1/4] PHPCS" ...@@ -95,10 +95,9 @@ print_title "[1/4] PHPCS"
$CORE_DIRECTORY/vendor/bin/phpcs $MODULE_DIRECTORY -ps --standard="$CORE_DIRECTORY/core/phpcs.xml.dist" $CORE_DIRECTORY/vendor/bin/phpcs $MODULE_DIRECTORY -ps --standard="$CORE_DIRECTORY/core/phpcs.xml.dist"
print_results $? "PHPCS" print_results $? "PHPCS"
# @todo Uncomment in https://drupal.org/i/3342120 print_title "[2/4] PHPStan"
# print_title "[2/4] PHPStan" php -d apc.enabled=0 -d apc.enable_cli=0 $CORE_DIRECTORY/vendor/bin/phpstan analyze --no-progress --configuration="$MODULE_DIRECTORY/phpstan.neon.dist" $MODULE_DIRECTORY
# php -d apc.enabled=0 -d apc.enable_cli=0 $CORE_DIRECTORY/vendor/bin/phpstan analyze --no-progress --configuration="$CORE_DIRECTORY/core/phpstan.neon.dist" $MODULE_DIRECTORY print_results $? "PHPStan"
# print_results $? "PHPStan"
print_title "[3/4] CSpell" print_title "[3/4] CSpell"
cd $CORE_DIRECTORY/core && yarn run -s spellcheck --no-progress --root $MODULE_DIRECTORY -c .cspell.json "**" && cd - cd $CORE_DIRECTORY/core && yarn run -s spellcheck --no-progress --root $MODULE_DIRECTORY -c .cspell.json "**" && cd -
......
...@@ -106,8 +106,8 @@ final class BatchProcessor { ...@@ -106,8 +106,8 @@ final class BatchProcessor {
* @see \Drupal\automatic_updates\Updater::stage() * @see \Drupal\automatic_updates\Updater::stage()
*/ */
public static function stage(array &$context): void { public static function stage(array &$context): void {
$stage_id = \Drupal::service('session')->get(static::STAGE_ID_SESSION_KEY);
try { try {
$stage_id = \Drupal::service('session')->get(static::STAGE_ID_SESSION_KEY);
static::getUpdater()->claim($stage_id)->stage(); static::getUpdater()->claim($stage_id)->stage();
} }
catch (\Throwable $e) { catch (\Throwable $e) {
......
...@@ -152,7 +152,7 @@ final class UpdaterForm extends UpdateFormBase { ...@@ -152,7 +152,7 @@ final class UpdaterForm extends UpdateFormBase {
$results = []; $results = [];
} }
else { else {
$results = $this->runStatusCheck($this->updater, $this->eventDispatcher, TRUE); $results = $this->runStatusCheck($this->updater, $this->eventDispatcher);
} }
$this->displayResults($results, $this->renderer); $this->displayResults($results, $this->renderer);
$project = $project_info->getProjectInfo(); $project = $project_info->getProjectInfo();
......
...@@ -69,7 +69,7 @@ final class StatusChecker implements EventSubscriberInterface { ...@@ -69,7 +69,7 @@ final class StatusChecker implements EventSubscriberInterface {
else { else {
$stage = $this->cronUpdater; $stage = $this->cronUpdater;
} }
$results = $this->runStatusCheck($stage, $this->eventDispatcher, TRUE); $results = $this->runStatusCheck($stage, $this->eventDispatcher);
$this->keyValueExpirable->setWithExpire( $this->keyValueExpirable->setWithExpire(
'status_check_last_run', 'status_check_last_run',
......
...@@ -103,6 +103,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface { ...@@ -103,6 +103,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface {
if ($updated_packages = array_filter($updated_packages, $filter)) { if ($updated_packages = array_filter($updated_packages, $filter)) {
$staged_packages = $stage->getInstalledPackages(); $staged_packages = $stage->getInstalledPackages();
$version_change_messages = [];
foreach ($updated_packages as $name => $updated_package) { foreach ($updated_packages as $name => $updated_package) {
$version_change_messages[] = $this->t( $version_change_messages[] = $this->t(
"@type '@name' from @active_version to @staged_version.", "@type '@name' from @active_version to @staged_version.",
...@@ -114,14 +115,12 @@ final class StagedProjectsValidator implements EventSubscriberInterface { ...@@ -114,14 +115,12 @@ final class StagedProjectsValidator implements EventSubscriberInterface {
] ]
); );
} }
if (!empty($version_change_messages)) { $version_change_summary = $this->formatPlural(
$version_change_summary = $this->formatPlural( count($version_change_messages),
count($version_change_messages), 'The update cannot proceed because the following Drupal project was unexpectedly updated. Only Drupal Core updates are currently supported.',
'The update cannot proceed because the following Drupal project was unexpectedly updated. Only Drupal Core updates are currently supported.', 'The update cannot proceed because the following Drupal projects were unexpectedly updated. Only Drupal Core updates are currently supported.'
'The update cannot proceed because the following Drupal projects were unexpectedly updated. Only Drupal Core updates are currently supported.' );
); $event->addError($version_change_messages, $version_change_summary);
$event->addError($version_change_messages, $version_change_summary);
}
} }
} }
......
...@@ -32,16 +32,15 @@ class ClickableHelpTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -32,16 +32,15 @@ class ClickableHelpTest extends AutomaticUpdatesFunctionalTestBase {
unset($this->disableValidators[array_search('package_manager.validator.composer_executable', $this->disableValidators)]); unset($this->disableValidators[array_search('package_manager.validator.composer_executable', $this->disableValidators)]);
parent::setUp(); parent::setUp();
$this->setReleaseMetadata(__DIR__ . '/../../../package_manager/tests/fixtures/release-history/drupal.9.8.1-security.xml'); $this->setReleaseMetadata(__DIR__ . '/../../../package_manager/tests/fixtures/release-history/drupal.9.8.1-security.xml');
$this->checkerRunnerUser = $this->createUser([
'administer site configuration',
]);
} }
/** /**
* Tests if composer executable is not present then the help link clickable. * Tests if composer executable is not present then the help link clickable.
*/ */
public function testHelpLinkClickable(): void { public function testHelpLinkClickable(): void {
$this->drupalLogin($this->checkerRunnerUser); $this->drupalLogin($this->createUser([
'administer site configuration',
]));
$this->config('package_manager.settings') $this->config('package_manager.settings')
->set('executables.composer', '/not/matching/path/to/composer') ->set('executables.composer', '/not/matching/path/to/composer')
->save(); ->save();
......
...@@ -50,7 +50,7 @@ class XdebugValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -50,7 +50,7 @@ class XdebugValidatorTest extends AutomaticUpdatesKernelTestBase {
$stage->require(['drupal/random']); $stage->require(['drupal/random']);
$this->assertUpdateStagedTimes(1); $this->assertUpdateStagedTimes(1);
$event_dispatcher = \Drupal::service('event_dispatcher'); $event_dispatcher = \Drupal::service('event_dispatcher');
$result = $this->runStatusCheck($stage, $event_dispatcher, TRUE); $result = $this->runStatusCheck($stage, $event_dispatcher);
$this->assertSame($message->getUntranslatedString(), $result[0]->getMessages()[0]->getUntranslatedString()); $this->assertSame($message->getUntranslatedString(), $result[0]->getMessages()[0]->getUntranslatedString());
$stage->destroy(TRUE); $stage->destroy(TRUE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment