public function removeTask($removeTask, Application $application = null)
    {
        $removeApplicationName = $application instanceof Application ? $application->getName() : null;

        $applicationRemovalGuardClause = function ($applicationName) use ($removeApplicationName) {
            return null !== $removeApplicationName && $applicationName !== $removeApplicationName;
        };

        if (isset($this->tasks['stage'])) {
            foreach ($this->tasks['stage'] as $applicationName => $steps) {
                if ($applicationRemovalGuardClause($applicationName)) {
                    continue;
                }
                foreach ($steps as $step => $tasksByStageStep) {
                    foreach ($tasksByStageStep as $stageName => $tasks) {
                        $this->tasks['stage'][$applicationName][$step][$stageName] = array_filter($tasks, function ($task) use ($removeTask) {
                            return $task !== $removeTask;
                        });
                    }
                }
            }
        }
        if (isset($this->tasks['before'])) {
            foreach ($this->tasks['before'] as $applicationName => $tasksByTask) {
                if ($applicationRemovalGuardClause($applicationName)) {
                    continue;
                }
                foreach ($tasksByTask as $taskName => $tasks) {
                    $this->tasks['before'][$applicationName][$taskName] = array_filter($tasks, function ($task) use ($removeTask) {
                        return $task !== $removeTask;
                    });
                }
            }
        }
        if (isset($this->tasks['after'])) {
            foreach ($this->tasks['after'] as $applicationName => $tasksByTask) {
                if ($applicationRemovalGuardClause($applicationName)) {
                    continue;
                }
                foreach ($tasksByTask as $taskName => $tasks) {
                    $this->tasks['after'][$applicationName][$taskName] = array_filter($tasks, function ($task) use ($removeTask) {
                        return $task !== $removeTask;
                    });
                }
            }
        }

        return $this;
    }