3 * This file is part of the Version package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace SebastianBergmann;
14 * @since Class available since Release 1.0.0
23 * @param string $release
26 public function __construct($release, $path)
28 $this->release = $release;
35 public function getVersion()
37 if ($this->version === null) {
38 if (count(explode('.', $this->release)) == 3) {
39 $this->version = $this->release;
41 $this->version = $this->release . '-dev';
44 $git = $this->getGitInformation($this->path);
47 if (count(explode('.', $this->release)) == 3) {
48 $this->version = $git;
50 $git = explode('-', $git);
52 $this->version = $this->release . '-' . end($git);
57 return $this->version;
64 private function getGitInformation($path)
66 if (!is_dir($path . DIRECTORY_SEPARATOR . '.git')) {
73 $result = @exec('git describe --tags 2>&1', $output, $returnCode);
76 if ($returnCode !== 0) {