public function applyPatch(Patch $patch, $baseDirectory)
    {
        $error = null;
        foreach ($patch->getLevels() as $patchLevel) {
            try {
                $this->applyPatchLevel($patch, $baseDirectory, $patchLevel);

                return;
            } catch (Exception\PatchAlreadyApplied $x) {
                throw $x;
            } catch (Exception\PatchNotApplied $x) {
                if ($error === null) {
                    $error = $x;
                }
            }
        }
        throw $error;
    }