Code Duplication    Length = 20-22 lines in 2 locations

src/Config/ConfigFileStorage.php 1 location

@@ 137-156 (lines=20) @@
134
     * @throws WriteException         If the file cannot be written.
135
     * @throws InvalidConfigException If the file contains invalid configuration.
136
     */
137
    public function saveConfigFile(ConfigFile $configFile)
138
    {
139
        try {
140
            $jsonData = $this->configFileConverter->toJson($configFile);
141
        } catch (ConversionFailedException $e) {
142
            throw new InvalidConfigException(sprintf(
143
                'The data written to %s could not be converted: %s',
144
                $configFile->getPath(),
145
                $e->getMessage()
146
            ), 0, $e);
147
        }
148
149
        $json = $this->encode($jsonData, $configFile->getPath());
150
151
        $this->storage->write($configFile->getPath(), $json);
152
153
        if ($this->factoryManager) {
154
            $this->factoryManager->autoGenerateFactoryClass();
155
        }
156
    }
157
158
    private function encode(stdClass $jsonData, $path)
159
    {

src/Module/ModuleFileStorage.php 1 location

@@ 210-231 (lines=22) @@
207
     * @throws WriteException         If the file cannot be written.
208
     * @throws InvalidConfigException If the file contains invalid configuration.
209
     */
210
    public function saveRootModuleFile(RootModuleFile $moduleFile)
211
    {
212
        try {
213
            $jsonData = $this->rootModuleFileConverter->toJson($moduleFile, array(
214
                'targetVersion' => $moduleFile->getVersion(),
215
            ));
216
        } catch (ConversionFailedException $e) {
217
            throw new InvalidConfigException(sprintf(
218
                'The data written to %s could not be converted: %s',
219
                $moduleFile->getPath(),
220
                $e->getMessage()
221
            ), 0, $e);
222
        }
223
224
        $json = $this->encode($jsonData, $moduleFile->getPath());
225
226
        $this->storage->write($moduleFile->getPath(), $json);
227
228
        if ($this->factoryManager) {
229
            $this->factoryManager->autoGenerateFactoryClass();
230
        }
231
    }
232
233
    private function encode(stdClass $jsonData, $path)
234
    {