public function checkPatches(Event $event)
    {
        if (!$this->isPatchingEnabled()) {
            return;
        }

        try {
            $repositoryManager = $this->composer->getRepositoryManager();
            $localRepository = $repositoryManager->getLocalRepository();
            $installationManager = $this->composer->getInstallationManager();
            $packages = $localRepository->getPackages();

            $tmp_patches = $this->grabPatches();
            foreach ($packages as $package) {
                $extra = $package->getExtra();
                if (isset($extra['patches'])) {
                    $this->installedPatches[$package->getName()] = $extra['patches'];
                }
                $patches = isset($extra['patches']) ? $extra['patches'] : array();
                $tmp_patches = Util::arrayMergeRecursiveDistinct($tmp_patches, $patches);
            }

            if ($tmp_patches === false) {
                $this->io->write('<info>No patches supplied.</info>');
                return;
            }

            // Remove packages for which the patch set has changed.
            foreach ($packages as $package) {
                if (!($package instanceof AliasPackage)) {
                    $package_name = $package->getName();
                    $extra = $package->getExtra();
                    $has_patches = isset($tmp_patches[$package_name]);
                    $has_applied_patches = isset($extra['patches_applied']);
                    if (($has_patches && !$has_applied_patches)
                        || (!$has_patches && $has_applied_patches)
                        || ($has_patches && $has_applied_patches &&
                            $tmp_patches[$package_name] !== $extra['patches_applied'])) {
                        $uninstallOperation = new UninstallOperation(
                            $package,
                            'Removing package so it can be re-installed and re-patched.'
                        );
                        $this->io->write('<info>Removing package ' .
                            $package_name .
                            ' so that it can be re-installed and re-patched.</info>');
                        $installationManager->uninstall($localRepository, $uninstallOperation);
                    }
                }
            }
        } catch (\LogicException $e) {
            // If the Locker isn't available, then we don't need to do this.
            // It's the first time packages have been installed.
            return;
        }
    }