/**
  * Write a notice to IO
  *
  * @param string $action
  * @param \Netresearch\Composer\Patches\Patch $patch
  * @param \Composer\Package\PackageInterface $package
  */
 protected function writePatchNotice($action, Patch $patch, PackageInterface $package)
 {
     $adverbMap = array('test' => 'on', 'apply' => 'to', 'revert' => 'from');
     if ($action == 'test' && !$this->io->isVeryVerbose()) {
         return;
     }
     $msg = '  - ' . ucfirst($action) . 'ing patch';
     if ($this->io->isVerbose() || !isset($patch->title)) {
         $msg .= ' <info>' . $patch->getChecksum() . '</info>';
     }
     $msg .= ' ' . $adverbMap[$action];
     $msg .= ' <info>' . $package->getName() . '</info>';
     if ($this->io->isVerbose()) {
         ' (<comment>' . $package->getPrettyVersion() . '</comment>)';
     }
     if (isset($patch->title)) {
         $msg .= ': <comment>' . $patch->title . '</comment>';
     }
     $this->io->write($msg);
 }
 /**
  * Get the patches for a package, identified by name and version
  *
  * @param string $name
  * @param string $version
  *
  * @throws Exception
  *
  * @return Patch[]
  */
 public function getPatches($name, $version)
 {
     if (!is_array($this->patches)) {
         $this->source = $this->read($this->source);
         $this->patches = array();
     }
     if (!array_key_exists($name, $this->patches)) {
         $this->source[$name] = $this->read($this->source, $name);
         $this->patches[$name] = array();
     }
     if (!array_key_exists($version, $this->patches[$name])) {
         $patchInfos = $this->read($this->source[$name]);
         if ($this->isPatch($patchInfos)) {
             $rawPatches = array($patchInfos);
         } else {
             $rawPatches = array();
             $hasConstraints = null;
             $requiredConstraint = new VersionConstraint('==', $version);
             $versionParser = new VersionParser();
             foreach ($patchInfos as $constraint => $patchInfo) {
                 if ($this->isPatch($patchInfo)) {
                     $isConstraint = false;
                     $rawPatches[] = $patchInfo;
                 } else {
                     $patchInfo = $this->read($patchInfo);
                     $isConstraint = true;
                     $constraint = $versionParser->parseConstraints($constraint);
                     if ($constraint->matches($requiredConstraint)) {
                         foreach ($patchInfo as $i => $rawPatch) {
                             if (!$this->isPatch($rawPatch)) {
                                 throw new Exception("Entry {$name}.{$constraint}[{$i}] is not a valid patch");
                             }
                             $rawPatches[] = $rawPatch;
                         }
                     }
                 }
                 if ($hasConstraints !== null) {
                     if ($hasConstraints !== $isConstraint) {
                         throw new Exception('Mixing patches with constraints and without constraints is not possible');
                     }
                 } else {
                     $hasConstraints = $isConstraint;
                 }
             }
         }
         $patches = array();
         foreach ($rawPatches as $rawPatch) {
             $patch = new Patch((object) $rawPatch, $this);
             $patches[$patch->getChecksum()] = $patch;
         }
         $this->patches[$name][$version] = $patches;
     }
     return $this->patches[$name][$version];
 }
 /**
  * Write a notice to IO
  *
  * @param string $action
  * @param \Netresearch\Composer\Patches\Patch $patch
  * @param \Composer\Package\PackageInterface $package
  * @param \Netresearch\Composer\Patches\Exception $exception
  */
 protected function writePatchNotice($action, Patch $patch, PackageInterface $package, $exception = null)
 {
     $adverbMap = array('test' => 'on', 'apply' => 'to', 'revert' => 'from');
     if ($action == 'test' && !$this->io->isVeryVerbose()) {
         return;
     }
     $msg = '  ' . ucfirst($action) . 'ing patch';
     if ($this->io->isVerbose() || !isset($patch->title)) {
         $msg .= ' <info>' . $patch->getChecksum() . '</info>';
     }
     $msg .= ' ' . $adverbMap[$action];
     $msg .= ' <info>' . $package->getName() . '</info>';
     if ($this->io->isVerbose()) {
         ' (<comment>' . $package->getPrettyVersion() . '</comment>)';
     }
     if (isset($patch->title)) {
         $msg .= ': <comment>' . $patch->title . '</comment>';
     }
     $this->io->write($msg);
     if ($exception) {
         $this->io->write('  <warning>Could not ' . $action . ' patch</warning>' . ($action == 'revert' ? ' (was probably not applied)' : ''));
         if ($this->io->isVerbose()) {
             $this->io->write('<warning>' . $exception->getMessage() . '</warning>');
         }
     }
 }