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