Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
14 / 14
MethodReturnType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
8
100.00% covered (success)
100.00%
14 / 14
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 generatePHPDoc
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
 generateSignatureReturnType
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
7 / 7
<?php
namespace Siesta\CodeGenerator;
use Siesta\Util\StringUtil;
class MethodReturnType
{
    protected $type;
    protected $nullAble;
    /**
     * MethodReturnType constructor.
     *
     * @param string|null $type
     * @param bool $nullAble
     */
    public function __construct(string $type = null, bool $nullAble = false)
    {
        $this->type = $type;
        $this->nullAble = $nullAble;
    }
    /**
     * @return string
     */
    public function generatePHPDoc()
    {
        if ($this->type === null) {
            return '@return void';
        }
        $optional = $this->nullAble ? '|null' : '';
        return '@return ' . $this->type . $optional;
    }
    /**
     * @return null|string
     */
    public function generateSignatureReturnType()
    {
        if ($this->type === null) {
            return '';
        }
        if ($this->nullAble) {
            return '';
        }
        if (StringUtil::endsWith($this->type, "[]")) {
            return ' : array';
        }
        return ' : ' . $this->type;
    }
}