xref: /dokuwiki/inc/Remote/OpenApiDoc/DocBlockProperty.php (revision 093fe67e98c0cdb4b73fd46938e49b64971483c2)
18ddd9b69SAndreas Gohr<?php
28ddd9b69SAndreas Gohr
38ddd9b69SAndreas Gohrnamespace dokuwiki\Remote\OpenApiDoc;
48ddd9b69SAndreas Gohr
58ddd9b69SAndreas Gohrclass DocBlockProperty extends DocBlock
68ddd9b69SAndreas Gohr{
78ddd9b69SAndreas Gohr    /** @var Type */
88ddd9b69SAndreas Gohr    protected $type;
98ddd9b69SAndreas Gohr
108ddd9b69SAndreas Gohr    /**
118ddd9b69SAndreas Gohr     * Parse the given docblock
128ddd9b69SAndreas Gohr     *
138ddd9b69SAndreas Gohr     * The docblock can be of a method, class or property.
148ddd9b69SAndreas Gohr     *
158ddd9b69SAndreas Gohr     * @param \ReflectionProperty $reflector
168ddd9b69SAndreas Gohr     */
178ddd9b69SAndreas Gohr    public function __construct(\ReflectionProperty $reflector)
188ddd9b69SAndreas Gohr    {
198ddd9b69SAndreas Gohr        parent::__construct($reflector);
208ddd9b69SAndreas Gohr        $this->refineVar();
218ddd9b69SAndreas Gohr    }
228ddd9b69SAndreas Gohr
238ddd9b69SAndreas Gohr    /**
248ddd9b69SAndreas Gohr     * The Type of this property
258ddd9b69SAndreas Gohr     *
268ddd9b69SAndreas Gohr     * @return Type
278ddd9b69SAndreas Gohr     */
288ddd9b69SAndreas Gohr    public function getType()
298ddd9b69SAndreas Gohr    {
308ddd9b69SAndreas Gohr        return $this->type;
318ddd9b69SAndreas Gohr    }
328ddd9b69SAndreas Gohr
338ddd9b69SAndreas Gohr    /**
348ddd9b69SAndreas Gohr     * Parse the var tag into its components
358ddd9b69SAndreas Gohr     *
368ddd9b69SAndreas Gohr     * @return void
378ddd9b69SAndreas Gohr     */
388ddd9b69SAndreas Gohr    protected function refineVar()
398ddd9b69SAndreas Gohr    {
408ddd9b69SAndreas Gohr        $refType = $this->reflector->getType();
418ddd9b69SAndreas Gohr        $this->type = new Type($refType ? $refType->getName() : 'string', $this->getContext());
428ddd9b69SAndreas Gohr
438ddd9b69SAndreas Gohr
448ddd9b69SAndreas Gohr        if (!isset($this->tags['var'])) return;
458ddd9b69SAndreas Gohr
46*093fe67eSAndreas Gohr        [$type, $description] = array_map(trim(...), sexplode(' ', $this->tags['var'][0], 2, ''));
478ddd9b69SAndreas Gohr        $this->type = new Type($type, $this->getContext());
488ddd9b69SAndreas Gohr        $this->summary = $description;
498ddd9b69SAndreas Gohr    }
508ddd9b69SAndreas Gohr}
51