console-helpers /
svn-buddy
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the SVN-Buddy library. |
||
| 4 | * For the full copyright and license information, please view |
||
| 5 | * the LICENSE file that was distributed with this source code. |
||
| 6 | * |
||
| 7 | * @copyright Alexander Obuhovich <[email protected]> |
||
| 8 | * @link https://github.com/console-helpers/svn-buddy |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace ConsoleHelpers\SVNBuddy\Repository; |
||
| 12 | |||
| 13 | |||
| 14 | use ConsoleHelpers\SVNBuddy\Command\ConflictsCommand; |
||
| 15 | use ConsoleHelpers\SVNBuddy\Config\CommandConfig; |
||
| 16 | use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
||
| 17 | |||
| 18 | class WorkingCopyConflictTracker |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Repository connector |
||
| 23 | * |
||
| 24 | * @var Connector |
||
| 25 | */ |
||
| 26 | protected $repositoryConnector; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Command config. |
||
| 30 | * |
||
| 31 | * @var CommandConfig |
||
| 32 | */ |
||
| 33 | protected $commandConfig; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Conflicts command. |
||
| 37 | * |
||
| 38 | * @var ConflictsCommand |
||
| 39 | */ |
||
| 40 | protected $conflictsCommand; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Creates working copy conflict tracker instance. |
||
| 44 | * |
||
| 45 | * @param Connector $repository_connector Repository connector. |
||
| 46 | * @param CommandConfig $command_config Command config. |
||
| 47 | */ |
||
| 48 | 11 | public function __construct(Connector $repository_connector, CommandConfig $command_config) |
|
| 49 | { |
||
| 50 | 11 | $this->repositoryConnector = $repository_connector; |
|
| 51 | 11 | $this->commandConfig = $command_config; |
|
| 52 | 11 | $this->conflictsCommand = new ConflictsCommand(); |
|
| 53 | 11 | } |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Adds new conflicts to previously recorded. |
||
| 57 | * |
||
| 58 | * @param string $wc_path Working copy path. |
||
| 59 | * |
||
| 60 | * @return void |
||
| 61 | * @throws \LogicException When working copy has no conflicts. |
||
| 62 | */ |
||
| 63 | 3 | public function add($wc_path) |
|
| 64 | { |
||
| 65 | 3 | $new_conflicts = $this->getNewConflicts($wc_path); |
|
| 66 | |||
| 67 | 3 | if ( !$new_conflicts ) { |
|
|
1 ignored issue
–
show
|
|||
| 68 | 1 | throw new \LogicException('The working copy at "' . $wc_path . '" has no conflicts to be added.'); |
|
| 69 | } |
||
| 70 | |||
| 71 | 2 | $this->setRecordedConflicts( |
|
| 72 | 2 | $wc_path, |
|
| 73 | 2 | array_unique(array_merge($this->getRecordedConflicts($wc_path), $new_conflicts)) |
|
| 74 | 2 | ); |
|
| 75 | 2 | } |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Replaces previously recorded conflicts with new ones. |
||
| 79 | * |
||
| 80 | * @param string $wc_path Working copy path. |
||
| 81 | * |
||
| 82 | * @return void |
||
| 83 | * @throws \LogicException When working copy has no conflicts. |
||
| 84 | */ |
||
| 85 | 3 | public function replace($wc_path) |
|
| 86 | { |
||
| 87 | 3 | $new_conflicts = $this->getNewConflicts($wc_path); |
|
| 88 | |||
| 89 | 3 | if ( !$new_conflicts ) { |
|
|
1 ignored issue
–
show
The expression
$new_conflicts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 90 | 1 | throw new \LogicException('The working copy at "' . $wc_path . '" has no conflicts to be added.'); |
|
| 91 | } |
||
| 92 | |||
| 93 | 2 | $this->setRecordedConflicts($wc_path, $new_conflicts); |
|
| 94 | 2 | } |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Erases previously recorded conflicts. |
||
| 98 | * |
||
| 99 | * @param string $wc_path Working copy path. |
||
| 100 | * |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | 1 | public function erase($wc_path) |
|
| 104 | { |
||
| 105 | 1 | $this->setRecordedConflicts($wc_path, array()); |
|
| 106 | 1 | } |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Returns previously recoded conflicts. |
||
| 110 | * |
||
| 111 | * @param string $wc_path Working copy path. |
||
| 112 | * |
||
| 113 | * @return array |
||
| 114 | */ |
||
| 115 | 7 | public function getNewConflicts($wc_path) |
|
| 116 | { |
||
| 117 | 7 | return $this->repositoryConnector->getWorkingCopyConflicts($wc_path); |
|
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Returns previously recoded conflicts. |
||
| 122 | * |
||
| 123 | * @param string $wc_path Working copy path. |
||
| 124 | * |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | 6 | public function getRecordedConflicts($wc_path) |
|
| 128 | { |
||
| 129 | 6 | return $this->commandConfig->getSettingValue( |
|
| 130 | 6 | ConflictsCommand::SETTING_CONFLICTS_RECORDED_CONFLICTS, |
|
| 131 | 6 | $this->conflictsCommand, |
|
| 132 | $wc_path |
||
| 133 | 6 | ); |
|
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Returns previously recoded conflicts. |
||
| 138 | * |
||
| 139 | * @param string $wc_path Working copy path. |
||
| 140 | * @param array $conflicts Conflicts. |
||
| 141 | * |
||
| 142 | * @return void |
||
| 143 | */ |
||
| 144 | 5 | protected function setRecordedConflicts($wc_path, array $conflicts) |
|
| 145 | { |
||
| 146 | 5 | $this->commandConfig->setSettingValue( |
|
| 147 | 5 | ConflictsCommand::SETTING_CONFLICTS_RECORDED_CONFLICTS, |
|
| 148 | 5 | $this->conflictsCommand, |
|
| 149 | 5 | $wc_path, |
|
| 150 | $conflicts |
||
| 151 | 5 | ); |
|
| 152 | 5 | } |
|
| 153 | |||
| 154 | } |
||
| 155 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.