for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace KevinGH\Box\Compactor;
/**
* Compacts JSON files by re-encoding without pretty print.
final class Json extends FileExtensionCompactor
{
* {@inheritdoc}
public function __construct(array $extensions = ['json'])
parent::__construct($extensions);
}
protected function compactContent(string $contents): string
$decodedContents = json_decode($contents);
if (JSON_ERROR_NONE !== json_last_error()) {
return $contents;
return json_encode($decodedContents);