Merge pull request #9286 from bezpiatovs/refactored-operations

Refactor Operations classes to get rid of explicit strings comparison
main
Jordi Boggiano 4 years ago committed by GitHub
commit 8e888bec78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,15 +19,15 @@ use Composer\Package\PackageInterface;
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class InstallOperation implements OperationInterface
class InstallOperation extends SolverOperation implements OperationInterface
{
protected $package;
const TYPE = 'install';
/**
* Initializes operation.
*
* @param PackageInterface $package package instance
* @var PackageInterface
*/
protected $package;
public function __construct(PackageInterface $package)
{
$this->package = $package;
@ -43,16 +43,6 @@ class InstallOperation implements OperationInterface
return $this->package;
}
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'install';
}
/**
* {@inheritDoc}
*/
@ -65,12 +55,4 @@ class InstallOperation implements OperationInterface
{
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
}

@ -20,15 +20,15 @@ use Composer\Package\PackageInterface;
*
* @author Nils Adermann <naderman@naderman.de>
*/
class MarkAliasInstalledOperation implements OperationInterface
class MarkAliasInstalledOperation extends SolverOperation implements OperationInterface
{
protected $package;
const TYPE = 'markAliasInstalled';
/**
* Initializes operation.
*
* @param AliasPackage $package package instance
* @var AliasPackage
*/
protected $package;
public function __construct(AliasPackage $package)
{
$this->package = $package;
@ -37,23 +37,13 @@ class MarkAliasInstalledOperation implements OperationInterface
/**
* Returns package instance.
*
* @return PackageInterface
* @return AliasPackage
*/
public function getPackage()
{
return $this->package;
}
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'markAliasInstalled';
}
/**
* {@inheritDoc}
*/
@ -61,12 +51,4 @@ class MarkAliasInstalledOperation implements OperationInterface
{
return 'Marking <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>) as installed, alias of <info>'.$this->package->getAliasOf()->getPrettyName().'</info> (<comment>'.$this->package->getAliasOf()->getFullPrettyVersion().'</comment>)';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
}

@ -20,15 +20,15 @@ use Composer\Package\PackageInterface;
*
* @author Nils Adermann <naderman@naderman.de>
*/
class MarkAliasUninstalledOperation implements OperationInterface
class MarkAliasUninstalledOperation extends SolverOperation implements OperationInterface
{
protected $package;
const TYPE = 'markAliasUninstalled';
/**
* Initializes operation.
*
* @param AliasPackage $package package instance
* @var AliasPackage
*/
protected $package;
public function __construct(AliasPackage $package)
{
$this->package = $package;
@ -37,23 +37,13 @@ class MarkAliasUninstalledOperation implements OperationInterface
/**
* Returns package instance.
*
* @return PackageInterface
* @return AliasPackage
*/
public function getPackage()
{
return $this->package;
}
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'markAliasUninstalled';
}
/**
* {@inheritDoc}
*/
@ -61,12 +51,4 @@ class MarkAliasUninstalledOperation implements OperationInterface
{
return 'Marking <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>) as uninstalled, alias of <info>'.$this->package->getAliasOf()->getPrettyName().'</info> (<comment>'.$this->package->getAliasOf()->getFullPrettyVersion().'</comment>)';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
}

@ -0,0 +1,43 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver\Operation;
use Composer\Package\PackageInterface;
/**
* Abstract operation class.
*
* @author Aleksandr Bezpiatov <aleksandr.bezpiatov@spryker.com>
*/
abstract class SolverOperation implements OperationInterface
{
const TYPE = null;
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return static::TYPE;
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
}

@ -19,15 +19,15 @@ use Composer\Package\PackageInterface;
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class UninstallOperation implements OperationInterface
class UninstallOperation extends SolverOperation implements OperationInterface
{
protected $package;
const TYPE = 'uninstall';
/**
* Initializes operation.
*
* @param PackageInterface $package package instance
* @var PackageInterface
*/
protected $package;
public function __construct(PackageInterface $package)
{
$this->package = $package;
@ -43,16 +43,6 @@ class UninstallOperation implements OperationInterface
return $this->package;
}
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'uninstall';
}
/**
* {@inheritDoc}
*/
@ -65,12 +55,4 @@ class UninstallOperation implements OperationInterface
{
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
}

@ -20,14 +20,21 @@ use Composer\Package\Version\VersionParser;
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class UpdateOperation implements OperationInterface
class UpdateOperation extends SolverOperation implements OperationInterface
{
const TYPE = 'update';
/**
* @var PackageInterface
*/
protected $initialPackage;
/**
* @var PackageInterface
*/
protected $targetPackage;
/**
* Initializes update operation.
*
* @param PackageInterface $initial initial package
* @param PackageInterface $target target package (updated)
*/
@ -57,16 +64,6 @@ class UpdateOperation implements OperationInterface
return $this->targetPackage;
}
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'update';
}
/**
* {@inheritDoc}
*/
@ -92,12 +89,4 @@ class UpdateOperation implements OperationInterface
return $actionName.' <info>'.$initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
}

Loading…
Cancel
Save