Skip to content

Commit 118f981

Browse files
GrahamCampbellkeradus
authored andcommitted
Support property, property-read and property-write tags
1 parent 6dc7832 commit 118f981

File tree

7 files changed

+67
-4
lines changed

7 files changed

+67
-4
lines changed

Symfony/CS/AbstractPhpdocTypesFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class AbstractPhpdocTypesFixer extends AbstractFixer
2727
*
2828
* @var string[]
2929
*/
30-
protected static $tags = array('param', 'return', 'type', 'var', 'property');
30+
protected static $tags = array('param', 'property', 'property-read', 'property-write', 'return', 'type', 'var');
3131

3232
/**
3333
* {@inheritdoc}

Symfony/CS/DocBlock/Tag.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class Tag
2626
private static $tags = array(
2727
'api', 'author', 'category', 'copyright', 'deprecated', 'example',
2828
'global', 'internal', 'license', 'link', 'method', 'package', 'param',
29-
'property', 'return', 'see', 'since', 'struct', 'subpackage', 'throws',
30-
'todo', 'typedef', 'uses', 'var', 'version',
29+
'property', 'property-read', 'property-write', 'return', 'see',
30+
'since', 'struct', 'subpackage', 'throws', 'todo', 'typedef', 'uses',
31+
'var', 'version',
3132
);
3233

3334
/**
@@ -45,7 +46,7 @@ class Tag
4546
public function __construct($content)
4647
{
4748
$this->name = 'other';
48-
preg_match_all('/@[a-zA-Z0-9_]+(?=\s|$)/', $content, $matches);
49+
preg_match_all('/@[a-zA-Z0-9_-]+(?=\s|$)/', $content, $matches);
4950

5051
if (isset($matches[0][0])) {
5152
$this->name = ltrim($matches[0][0], '@');

Symfony/CS/DocBlock/TagComparator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TagComparator
2828
array('deprecated', 'link', 'see', 'since'),
2929
array('author', 'copyright', 'license'),
3030
array('package', 'subpackage'),
31+
array('property', 'property-read', 'property-write'),
3132
);
3233

3334
/**

Symfony/CS/Tests/DocBlock/TagTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function provideNameCases()
3737
array('THROWSSS', "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"),
3838
array('other', ' * @\Foo\Bar(baz = 123)'),
3939
array('expectedException', ' * @expectedException Exception'),
40+
array('property-read', ' * @property-read integer $daysInMonth number of days in the given month'),
4041
array('method', ' * @method'),
4142
array('method', ' * @method string getString()'),
4243
array('other', ' * @method("GET")'),
@@ -61,6 +62,7 @@ public function provideValidCases()
6162
array(true, '*@throws \Exception'),
6263
array(true, ' * @method'),
6364
array(true, ' * @method string getString()'),
65+
array(true, ' * @property-read integer $daysInMonth number of days in the given month'),
6466
array(false, ' * @method("GET")'),
6567
array(false, '*@thRoWs \InvalidArgumentException'),
6668
array(false, "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"),

Symfony/CS/Tests/Fixer/Symfony/PhpdocScalarFixerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function testPropertyFix()
4545
<?php
4646
/**
4747
* @property int $foo
48+
* @property-read bool $bar
49+
* @property-write float $baz
4850
*/
4951

5052
EOF;
@@ -53,6 +55,8 @@ public function testPropertyFix()
5355
<?php
5456
/**
5557
* @property integer $foo
58+
* @property-read boolean $bar
59+
* @property-write double $baz
5660
*/
5761

5862
EOF;

Symfony/CS/Tests/Fixer/Symfony/PhpdocSeparationFixerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,36 @@ public function testDeprecatedAndSeeTags()
343343
* @return void
344344
*/
345345

346+
EOF;
347+
348+
$this->makeTest($expected, $input);
349+
}
350+
351+
public function testPropertyTags()
352+
{
353+
$expected = <<<'EOF'
354+
<?php
355+
/**
356+
* @author Bar Baz <[email protected]>
357+
*
358+
* @property int $foo
359+
* @property-read int $foo
360+
* @property-write int $bar
361+
*/
362+
363+
EOF;
364+
365+
$input = <<<'EOF'
366+
<?php
367+
/**
368+
* @author Bar Baz <[email protected]>
369+
* @property int $foo
370+
*
371+
* @property-read int $foo
372+
*
373+
* @property-write int $bar
374+
*/
375+
346376
EOF;
347377

348378
$this->makeTest($expected, $input);

Symfony/CS/Tests/Fixer/Symfony/PhpdocTypesFixerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ public function testMixedAndVoid()
9090
$this->makeTest($expected, $input);
9191
}
9292

93+
public function testPropertyFix()
94+
{
95+
$expected = <<<'EOF'
96+
<?php
97+
/**
98+
* @property int $foo
99+
* @property-read boolean $bar
100+
* @property-write mixed $baz
101+
*/
102+
103+
EOF;
104+
105+
$input = <<<'EOF'
106+
<?php
107+
/**
108+
* @property Int $foo
109+
* @property-read Boolean $bar
110+
* @property-write MIXED $baz
111+
*/
112+
113+
EOF;
114+
115+
$this->makeTest($expected, $input);
116+
}
117+
93118
public function testInlineDoc()
94119
{
95120
$expected = <<<'EOF'

0 commit comments

Comments
 (0)