xref: /dokuwiki/inc/Remote/OpenApiDoc/DocBlockProperty.php (revision d48c2b252a339bed693da46fae768d93f4b3fe41)
1*8ddd9b69SAndreas Gohr<?php
2*8ddd9b69SAndreas Gohr
3*8ddd9b69SAndreas Gohrnamespace dokuwiki\Remote\OpenApiDoc;
4*8ddd9b69SAndreas Gohr
5*8ddd9b69SAndreas Gohrclass DocBlockProperty extends DocBlock
6*8ddd9b69SAndreas Gohr{
7*8ddd9b69SAndreas Gohr    /** @var Type */
8*8ddd9b69SAndreas Gohr    protected $type;
9*8ddd9b69SAndreas Gohr
10*8ddd9b69SAndreas Gohr    /**
11*8ddd9b69SAndreas Gohr     * Parse the given docblock
12*8ddd9b69SAndreas Gohr     *
13*8ddd9b69SAndreas Gohr     * The docblock can be of a method, class or property.
14*8ddd9b69SAndreas Gohr     *
15*8ddd9b69SAndreas Gohr     * @param \ReflectionProperty $reflector
16*8ddd9b69SAndreas Gohr     */
17*8ddd9b69SAndreas Gohr    public function __construct(\ReflectionProperty $reflector)
18*8ddd9b69SAndreas Gohr    {
19*8ddd9b69SAndreas Gohr        parent::__construct($reflector);
20*8ddd9b69SAndreas Gohr        $this->refineVar();
21*8ddd9b69SAndreas Gohr    }
22*8ddd9b69SAndreas Gohr
23*8ddd9b69SAndreas Gohr    /**
24*8ddd9b69SAndreas Gohr     * The Type of this property
25*8ddd9b69SAndreas Gohr     *
26*8ddd9b69SAndreas Gohr     * @return Type
27*8ddd9b69SAndreas Gohr     */
28*8ddd9b69SAndreas Gohr    public function getType()
29*8ddd9b69SAndreas Gohr    {
30*8ddd9b69SAndreas Gohr        return $this->type;
31*8ddd9b69SAndreas Gohr    }
32*8ddd9b69SAndreas Gohr
33*8ddd9b69SAndreas Gohr    /**
34*8ddd9b69SAndreas Gohr     * Parse the var tag into its components
35*8ddd9b69SAndreas Gohr     *
36*8ddd9b69SAndreas Gohr     * @return void
37*8ddd9b69SAndreas Gohr     */
38*8ddd9b69SAndreas Gohr    protected function refineVar()
39*8ddd9b69SAndreas Gohr    {
40*8ddd9b69SAndreas Gohr        $refType = $this->reflector->getType();
41*8ddd9b69SAndreas Gohr        $this->type = new Type($refType ? $refType->getName() : 'string', $this->getContext());
42*8ddd9b69SAndreas Gohr
43*8ddd9b69SAndreas Gohr
44*8ddd9b69SAndreas Gohr        if (!isset($this->tags['var'])) return;
45*8ddd9b69SAndreas Gohr
46*8ddd9b69SAndreas Gohr        [$type, $description] = array_map('trim', sexplode(' ', $this->tags['var'][0], 2, ''));
47*8ddd9b69SAndreas Gohr        $this->type = new Type($type, $this->getContext());
48*8ddd9b69SAndreas Gohr        $this->summary = $description;
49*8ddd9b69SAndreas Gohr    }
50*8ddd9b69SAndreas Gohr}
51