Skip to content

Commit

Permalink
Update code to use a class that did not move between PS 1.7 & 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Feb 2, 2023
1 parent 0785d39 commit b2b419b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ parameters:
- vendor/autoload.php
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- "#Negated boolean expression is always false.#"
- '#Method PrestaShop\\PrestaShop\\Core\\Addon\\Module\\ModuleManager::install\(\) invoked with 2 parameters, 1 required.#'

level: max
17 changes: 6 additions & 11 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Prestashop\ModuleLibGuzzleAdapter\ClientFactory;
use Prestashop\ModuleLibGuzzleAdapter\Interfaces\HttpClientInterface;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use PrestaShop\PrestaShop\Core\Module\ModuleManager;

class Installer
{
Expand All @@ -20,9 +19,9 @@ class Installer
protected $marketplaceClient;

/**
* @var ModuleManager
* @var ModuleManagerBuilder
*/
protected $moduleManager;
protected $moduleManagerBuilder;

/**
* @var string
Expand All @@ -35,17 +34,13 @@ class Installer
public function __construct($prestashopVersion)
{
$moduleManagerBuilder = ModuleManagerBuilder::getInstance();
if (!$moduleManagerBuilder) {
if (is_null($moduleManagerBuilder)) {
throw new \Exception('ModuleManagerBuilder::getInstance() failed');
}

$this->marketplaceClient = (new ClientFactory())->getClient(['base_uri' => self::ADDONS_URL]);
$this->moduleManager = $moduleManagerBuilder->build();
$this->moduleManagerBuilder = $moduleManagerBuilder;
$this->prestashopVersion = $prestashopVersion;

if (!$this->moduleManager) {
throw new \Exception('ModuleManagerBuilder::getInstance() failed');
}
}

/**
Expand All @@ -58,10 +53,10 @@ public function installModule()
// On PrestaShop 1.7, the signature is install($source), with $source a module name or a path to an archive.
// On PrestaShop 8, the signature is install(string $name, $source = null).
if (version_compare($this->prestashopVersion, '8.0.0', '>=')) {
return $this->moduleManager->install(self::MODULE_NAME, $this->downloadModule());
return $this->moduleManagerBuilder->build()->install(self::MODULE_NAME, $this->downloadModule());
}

return $this->moduleManager->install(self::MODULE_NAME);
return $this->moduleManagerBuilder->build()->install(self::MODULE_NAME);
}

/**
Expand Down

0 comments on commit b2b419b

Please sign in to comment.