Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
CRAP
90.91% covered (success)
90.91%
10 / 11
SourceFile
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
4.01
90.91% covered (success)
90.91%
10 / 11
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getFilename
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 1
2.01
87.50% covered (warning)
87.50%
7 / 8
<?php declare(strict_types = 1);
/*
 * Copyright (c) 2019, Josef Kufner  <josef@kufner.cz>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
namespace Smalldb\StateMachine\SourcesExtension\Definition;
use JsonSerializable;
use Smalldb\StateMachine\Utils\SimpleJsonSerializableTrait;
class SourceFile implements JsonSerializable
{
    private string $filename;
    public function __construct(string $filename)
    {
        $this->filename = $filename;
    }
    public function getFilename(): string
    {
        return $this->filename;
    }
    public function jsonSerialize()
    {
        $curPath = getcwd() . DIRECTORY_SEPARATOR;
        $curPathLen = strlen($curPath);
        $filename = realpath($this->getFilename());
        if (strncmp($filename, $curPath, $curPathLen) === 0) {
            $relPath = substr($filename, $curPathLen);
        } else {
            $relPath = $filename;
        }
        return array_merge(get_object_vars($this), [
            "filename" => $relPath,
        ]);
    }
}