public function detectChanges()
    {
        if ($this->changedFiles === null || $this->changedPaths === null) {
            $this->loadDetectedDirectoriesAndFiles();
            $changesDetected = false;
            $this->changedPaths = $this->changedFiles = [];
            $this->changedFiles = $this->detectChangedFiles($this->monitoredFiles);

            foreach ($this->monitoredDirectories as $path => $filenamePattern) {
                $changesDetected = $this->detectChangesOnPath($path, $filenamePattern) ? true : $changesDetected;
            }

            if ($changesDetected) {
                $this->saveDetectedDirectoriesAndFiles();
            }
            $this->directoriesAndFiles = null;
        }

        $changedFileCount = count($this->changedFiles);
        $changedPathCount = count($this->changedPaths);

        if ($changedFileCount > 0) {
            $this->emitFilesHaveChanged($this->identifier, $this->changedFiles);
        }
        if ($changedPathCount > 0) {
            $this->emitDirectoriesHaveChanged($this->identifier, $this->changedPaths);
        }
        if ($changedFileCount > 0 || $changedPathCount) {
            $this->logger->info(sprintf('File Monitor "%s" detected %s changed files and %s changed directories.', $this->identifier, $changedFileCount, $changedPathCount), LogEnvironment::fromMethodName(__METHOD__));
        }
    }