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> * @author Konstantin Kudryashov <ever.zet@gmail.com>
*/ */
class InstallOperation implements OperationInterface class InstallOperation extends SolverOperation implements OperationInterface
{ {
protected $package; const TYPE = 'install';
/** /**
* Initializes operation. * @var PackageInterface
*
* @param PackageInterface $package package instance
*/ */
protected $package;
public function __construct(PackageInterface $package) public function __construct(PackageInterface $package)
{ {
$this->package = $package; $this->package = $package;
@ -43,16 +43,6 @@ class InstallOperation implements OperationInterface
return $this->package; return $this->package;
} }
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'install';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -65,12 +55,4 @@ class InstallOperation implements OperationInterface
{ {
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)'; 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> * @author Nils Adermann <naderman@naderman.de>
*/ */
class MarkAliasInstalledOperation implements OperationInterface class MarkAliasInstalledOperation extends SolverOperation implements OperationInterface
{ {
protected $package; const TYPE = 'markAliasInstalled';
/** /**
* Initializes operation. * @var AliasPackage
*
* @param AliasPackage $package package instance
*/ */
protected $package;
public function __construct(AliasPackage $package) public function __construct(AliasPackage $package)
{ {
$this->package = $package; $this->package = $package;
@ -37,23 +37,13 @@ class MarkAliasInstalledOperation implements OperationInterface
/** /**
* Returns package instance. * Returns package instance.
* *
* @return PackageInterface * @return AliasPackage
*/ */
public function getPackage() public function getPackage()
{ {
return $this->package; return $this->package;
} }
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'markAliasInstalled';
}
/** /**
* {@inheritDoc} * {@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>)'; 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> * @author Nils Adermann <naderman@naderman.de>
*/ */
class MarkAliasUninstalledOperation implements OperationInterface class MarkAliasUninstalledOperation extends SolverOperation implements OperationInterface
{ {
protected $package; const TYPE = 'markAliasUninstalled';
/** /**
* Initializes operation. * @var AliasPackage
*
* @param AliasPackage $package package instance
*/ */
protected $package;
public function __construct(AliasPackage $package) public function __construct(AliasPackage $package)
{ {
$this->package = $package; $this->package = $package;
@ -37,23 +37,13 @@ class MarkAliasUninstalledOperation implements OperationInterface
/** /**
* Returns package instance. * Returns package instance.
* *
* @return PackageInterface * @return AliasPackage
*/ */
public function getPackage() public function getPackage()
{ {
return $this->package; return $this->package;
} }
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'markAliasUninstalled';
}
/** /**
* {@inheritDoc} * {@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>)'; 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> * @author Konstantin Kudryashov <ever.zet@gmail.com>
*/ */
class UninstallOperation implements OperationInterface class UninstallOperation extends SolverOperation implements OperationInterface
{ {
protected $package; const TYPE = 'uninstall';
/** /**
* Initializes operation. * @var PackageInterface
*
* @param PackageInterface $package package instance
*/ */
protected $package;
public function __construct(PackageInterface $package) public function __construct(PackageInterface $package)
{ {
$this->package = $package; $this->package = $package;
@ -43,16 +43,6 @@ class UninstallOperation implements OperationInterface
return $this->package; return $this->package;
} }
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'uninstall';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -65,12 +55,4 @@ class UninstallOperation implements OperationInterface
{ {
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)'; 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> * @author Konstantin Kudryashov <ever.zet@gmail.com>
*/ */
class UpdateOperation implements OperationInterface class UpdateOperation extends SolverOperation implements OperationInterface
{ {
const TYPE = 'update';
/**
* @var PackageInterface
*/
protected $initialPackage; protected $initialPackage;
/**
* @var PackageInterface
*/
protected $targetPackage; protected $targetPackage;
/** /**
* Initializes update operation.
*
* @param PackageInterface $initial initial package * @param PackageInterface $initial initial package
* @param PackageInterface $target target package (updated) * @param PackageInterface $target target package (updated)
*/ */
@ -57,16 +64,6 @@ class UpdateOperation implements OperationInterface
return $this->targetPackage; return $this->targetPackage;
} }
/**
* Returns operation type.
*
* @return string
*/
public function getOperationType()
{
return 'update';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -92,12 +89,4 @@ class UpdateOperation implements OperationInterface
return $actionName.' <info>'.$initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)'; return $actionName.' <info>'.$initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)';
} }
/**
* {@inheritDoc}
*/
public function __toString()
{
return $this->show(false);
}
} }

Loading…
Cancel
Save