Code Duplication    Length = 24-28 lines in 3 locations

src/Console/Command/Cache/RebuildInternalCommand.php 3 locations

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