Code Duplication    Length = 24-28 lines in 3 locations

src/Command/RebuildCacheCommand.php 3 locations

@@ 42-69 (lines=28) @@
39
    /**
40
     * @param TaisiyaStyle $io
41
     */
42
    final protected function rebuildComposerSubscribersCache(TaisiyaStyle $io): void
43
    {
44
        $io->isVerbose() && $io->writeln('Rebuild Composer subscribers cache');
45
46
        $subscribers = [];
47
48
        $finder = Finder::create()
49
            ->in(TAISIYA_ROOT)
50
            ->path('/(src|vendor)/')
51
            ->files()
52
            ->name('*Subscriber.php');
53
54
        foreach ($finder as $k => $file) {
55
            $subscriberClass = $this->extractClassNameFromFile($file->getPathname());
56
            try {
57
                $reflectionClass = new \ReflectionClass($subscriberClass);
58
            } catch (\ReflectionException $e) {
59
                continue;
60
            }
61
            if (!$reflectionClass->isAbstract() && $reflectionClass->isSubclassOf(EventSubscriberInterface::class)) {
62
                $io->isVerbose() && $io->writeln('  + '.$subscriberClass);
63
                $subscribers[] = $subscriberClass;
64
            }
65
        }
66
67
        $this->putDataToCacheFile('composer_subscribers.cache.php', $subscribers);
68
        $io->isVerbose() && $io->writeln('  Subscribers saved to <info>composer_subscribers.cache.php</info>');
69
    }
70
71
    /**
72
     * @param TaisiyaStyle $io
@@ 74-97 (lines=24) @@
71
    /**
72
     * @param TaisiyaStyle $io
73
     */
74
    final protected function rebuildBundlesCache(TaisiyaStyle $io): void
75
    {
76
        $io->isVerbose() && $io->writeln('Rebuild bundles cache');
77
78
        $bundles = [];
79
80
        $finder = Finder::create()
81
            ->in(TAISIYA_ROOT)
82
            ->path('/(src|vendor)/')
83
            ->files()
84
            ->name('*ServiceProvider.php');
85
86
        foreach ($finder as $k => $file) {
87
            $bundleServiceProvider = $this->extractClassNameFromFile($file->getPathname());
88
            $reflectionClass = new \ReflectionClass($bundleServiceProvider);
89
            if (!$reflectionClass->isAbstract() && $reflectionClass->isSubclassOf(ServiceProvider::class)) {
90
                $io->isVerbose() && $io->writeln('  + '.$bundleServiceProvider);
91
                $bundles[] = $bundleServiceProvider;
92
            }
93
        }
94
95
        $this->putDataToCacheFile('bundles.cache.php', $bundles);
96
        $io->isVerbose() && $io->writeln('  Bundles saved to <info>bundles.cache.php</info>');
97
    }
98
99
    /**
100
     * @param TaisiyaStyle $io
@@ 102-129 (lines=28) @@
99
    /**
100
     * @param TaisiyaStyle $io
101
     */
102
    final protected function rebuildCommandsCache(TaisiyaStyle $io): void
103
    {
104
        $io->isVerbose() && $io->writeln('Rebuild commands cache');
105
106
        $commands = [];
107
108
        $finder = Finder::create()
109
            ->in(TAISIYA_ROOT)
110
            ->path('/(src|vendor)/')
111
            ->files()
112
            ->name('*Command.php');
113
114
        foreach ($finder as $k => $file) {
115
            $commandClass = $this->extractClassNameFromFile($file->getPathname());
116
            try {
117
                $reflectionClass = new \ReflectionClass($commandClass);
118
            } catch (\ReflectionException $e) {
119
                continue;
120
            }
121
            if (!$reflectionClass->isAbstract() && $reflectionClass->isSubclassOf(Command::class)) {
122
                $io->isVerbose() && $io->writeln('  + '.$commandClass);
123
                $commands[] = $commandClass;
124
            }
125
        }
126
127
        $this->putDataToCacheFile('commands.cache.php', $commands);
128
        $io->isVerbose() && $io->writeln('  Commands saved to <info>commands.cache.php</info>');
129
    }
130
131
    /**
132
     * @param string $filepath