<?php

namespace App\Service;

class VersionGetter
{
    public function __construct(private $projectDir)
    {
    }

    public function getVersion($defaultVersion = null): ?string
    {
        try {
            $data = json_decode(file_get_contents($this->projectDir.'/composer.json'), true);

            return isset($data['version']) ? $data['version'] : $defaultVersion;
        } catch (\Exception $exception) {
            return '';
        }
    }
}
