diff --git a/src/Composer/DependencyResolver/Operation/InstallOperation.php b/src/Composer/DependencyResolver/Operation/InstallOperation.php index a9f808101..6eefbd5bb 100644 --- a/src/Composer/DependencyResolver/Operation/InstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/InstallOperation.php @@ -19,15 +19,15 @@ use Composer\Package\PackageInterface; * * @author Konstantin Kudryashov */ -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 ').''.$package->getPrettyName().' ('.$package->getFullPrettyVersion().')'; } - - /** - * {@inheritDoc} - */ - public function __toString() - { - return $this->show(false); - } } diff --git a/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php b/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php index 9e3a9f17d..4c70257a3 100644 --- a/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php +++ b/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php @@ -20,15 +20,15 @@ use Composer\Package\PackageInterface; * * @author Nils Adermann */ -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 '.$this->package->getPrettyName().' ('.$this->package->getFullPrettyVersion().') as installed, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->package->getAliasOf()->getFullPrettyVersion().')'; } - - /** - * {@inheritDoc} - */ - public function __toString() - { - return $this->show(false); - } } diff --git a/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php b/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php index 16ca62ad9..08ed93ac3 100644 --- a/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php +++ b/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php @@ -20,15 +20,15 @@ use Composer\Package\PackageInterface; * * @author Nils Adermann */ -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 '.$this->package->getPrettyName().' ('.$this->package->getFullPrettyVersion().') as uninstalled, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->package->getAliasOf()->getFullPrettyVersion().')'; } - - /** - * {@inheritDoc} - */ - public function __toString() - { - return $this->show(false); - } } diff --git a/src/Composer/DependencyResolver/Operation/SolverOperation.php b/src/Composer/DependencyResolver/Operation/SolverOperation.php new file mode 100644 index 000000000..e1a78da84 --- /dev/null +++ b/src/Composer/DependencyResolver/Operation/SolverOperation.php @@ -0,0 +1,43 @@ + + * Jordi Boggiano + * + * 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 + */ +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); + } +} diff --git a/src/Composer/DependencyResolver/Operation/UninstallOperation.php b/src/Composer/DependencyResolver/Operation/UninstallOperation.php index 4fb39a6f6..585fdb1e5 100644 --- a/src/Composer/DependencyResolver/Operation/UninstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/UninstallOperation.php @@ -19,15 +19,15 @@ use Composer\Package\PackageInterface; * * @author Konstantin Kudryashov */ -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 '.$package->getPrettyName().' ('.$package->getFullPrettyVersion().')'; } - - /** - * {@inheritDoc} - */ - public function __toString() - { - return $this->show(false); - } } diff --git a/src/Composer/DependencyResolver/Operation/UpdateOperation.php b/src/Composer/DependencyResolver/Operation/UpdateOperation.php index 9e2fa99e5..543c8e783 100644 --- a/src/Composer/DependencyResolver/Operation/UpdateOperation.php +++ b/src/Composer/DependencyResolver/Operation/UpdateOperation.php @@ -20,14 +20,21 @@ use Composer\Package\Version\VersionParser; * * @author Konstantin Kudryashov */ -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.' '.$initialPackage->getPrettyName().' ('.$fromVersion.' => '.$toVersion.')'; } - - /** - * {@inheritDoc} - */ - public function __toString() - { - return $this->show(false); - } }