src/Reader/JsonReader.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

/**
 * Phoole (PHP7.2+)
 *
 * @category  Library
 * @package   Phoole\Base
 * @copyright Copyright (c) 2019 Hong Zhang
 */
declare(strict_types=1);

namespace Phoole\Base\Reader;

/**
 * JsonReader
 *
 * @package Phoole\Base
 */
class JsonReader extends AbstractReader
{
    /**
     * {@inheritDoc}
     */
    protected function readFromFile($path)
    {
        try {
            $data = \json_decode(\file_get_contents($path), TRUE);
            if ($data === NULL) {
                throw new \RuntimeException(\json_last_error_msg());
            }
        } catch (\Exception $e) {
            throw new \RuntimeException($e->getMessage());
        }
        return $data;
    }
}