Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 0f9ccce

Browse files
committed
Merge branch 'feature/170' into develop
Close #170
2 parents c6a4f08 + e59d7b3 commit 0f9ccce

9 files changed

+66
-25
lines changed

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 3.4.0 - TBD
6+
7+
### Added
8+
9+
- [#170](https://github.com/zendframework/zend-code/pull/170) adds class constant visibility modifiers support.
10+
11+
### Changed
12+
13+
- Nothing.
14+
15+
### Deprecated
16+
17+
- Nothing.
18+
19+
### Removed
20+
21+
- Nothing.
22+
23+
### Fixed
24+
25+
- Nothing.
26+
527
## 3.3.2 - 2019-08-31
628

729
### Added

src/Generator/PropertyGenerator.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ public function __construct($name = null, $defaultValue = null, $flags = self::F
157157
public function setConst($const)
158158
{
159159
if ($const) {
160-
$this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PRIVATE | self::FLAG_PROTECTED);
161160
$this->setFlags(self::FLAG_CONSTANT);
162161
} else {
163162
$this->removeFlag(self::FLAG_CONSTANT);
@@ -227,7 +226,7 @@ public function generate()
227226
$this->name
228227
));
229228
}
230-
$output .= $this->indentation . 'const ' . $name . ' = '
229+
$output .= $this->indentation . $this->getVisibility() . ' const ' . $name . ' = '
231230
. ($defaultValue !== null ? $defaultValue->generate() : 'null;');
232231

233232
return $output;

test/Generator/ClassGeneratorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ public function testClassCanBeGeneratedWithConstantAndPropertyWithSameName()
802802
class TestSampleSingleClass
803803
{
804804
805-
const fooProperty = 'duplicate';
805+
public const fooProperty = 'duplicate';
806806
807807
public $fooProperty = true;
808808

test/Generator/InterfaceGeneratorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ public function testCodeGenerationShouldTakeIntoAccountNamespacesFromReflection(
152152
interface FooInterface
153153
{
154154
155-
const BAR = 5;
155+
public const BAR = 5;
156156
157-
const FOO = 5;
157+
public const FOO = 5;
158158
159159
public function fooBarBaz();
160160

test/Generator/PropertyGeneratorTest.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Code\Generator;
1111

12+
use Generator;
1213
use PHPUnit\Framework\TestCase;
1314
use Zend\Code\Generator\DocBlock\Tag\VarTag;
1415
use Zend\Code\Generator\DocBlockGenerator;
@@ -126,10 +127,26 @@ public function testPropertyMultilineValue() : void
126127
self::assertEquals($expectedSource, $targetSource);
127128
}
128129

130+
public function visibility() : Generator
131+
{
132+
yield 'public' => [PropertyGenerator::FLAG_PUBLIC, 'public'];
133+
yield 'protected' => [PropertyGenerator::FLAG_PROTECTED, 'protected'];
134+
yield 'private' => [PropertyGenerator::FLAG_PRIVATE, 'private'];
135+
}
136+
137+
/**
138+
* @dataProvider visibility
139+
*/
140+
public function testPropertyCanProduceConstatWithVisibility(int $flag, string $visibility) : void
141+
{
142+
$codeGenProperty = new PropertyGenerator('FOO', 'bar', [PropertyGenerator::FLAG_CONSTANT, $flag]);
143+
self::assertSame(' ' . $visibility . ' const FOO = \'bar\';', $codeGenProperty->generate());
144+
}
145+
129146
public function testPropertyCanProduceContstantModifier() : void
130147
{
131148
$codeGenProperty = new PropertyGenerator('someVal', 'some string value', PropertyGenerator::FLAG_CONSTANT);
132-
self::assertEquals(' const someVal = \'some string value\';', $codeGenProperty->generate());
149+
self::assertEquals(' public const someVal = \'some string value\';', $codeGenProperty->generate());
133150
}
134151

135152
/**
@@ -139,7 +156,7 @@ public function testPropertyCanProduceContstantModifierWithSetter() : void
139156
{
140157
$codeGenProperty = new PropertyGenerator('someVal', 'some string value');
141158
$codeGenProperty->setConst(true);
142-
self::assertEquals(' const someVal = \'some string value\';', $codeGenProperty->generate());
159+
self::assertEquals(' public const someVal = \'some string value\';', $codeGenProperty->generate());
143160
}
144161

145162
public function testPropertyCanProduceStaticModifier() : void

test/Generator/ValueGeneratorTest.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,36 @@ public function validConstantTypes()
9292
return [
9393
[
9494
new PropertyValueGenerator([], PropertyValueGenerator::TYPE_ARRAY, ValueGenerator::OUTPUT_SINGLE_LINE),
95-
' const FOO = [];',
95+
' public const FOO = [];',
9696
],
9797
[
9898
new PropertyValueGenerator(
9999
[],
100100
PropertyValueGenerator::TYPE_ARRAY_LONG,
101101
ValueGenerator::OUTPUT_SINGLE_LINE
102102
),
103-
' const FOO = array();',
103+
' public const FOO = array();',
104104
],
105105
[
106106
new PropertyValueGenerator(
107107
[],
108108
PropertyValueGenerator::TYPE_ARRAY_SHORT,
109109
ValueGenerator::OUTPUT_SINGLE_LINE
110110
),
111-
' const FOO = [];',
111+
' public const FOO = [];',
112+
],
113+
[new PropertyValueGenerator(true, PropertyValueGenerator::TYPE_BOOL), ' public const FOO = true;'],
114+
[new PropertyValueGenerator(true, PropertyValueGenerator::TYPE_BOOLEAN), ' public const FOO = true;'],
115+
[new PropertyValueGenerator(1, PropertyValueGenerator::TYPE_INT), ' public const FOO = 1;'],
116+
[new PropertyValueGenerator(1, PropertyValueGenerator::TYPE_INTEGER), ' public const FOO = 1;'],
117+
[new PropertyValueGenerator(0.1, PropertyValueGenerator::TYPE_DOUBLE), ' public const FOO = 0.1;'],
118+
[new PropertyValueGenerator(0.1, PropertyValueGenerator::TYPE_FLOAT), ' public const FOO = 0.1;'],
119+
[new PropertyValueGenerator('bar', PropertyValueGenerator::TYPE_STRING), " public const FOO = 'bar';"],
120+
[new PropertyValueGenerator(null, PropertyValueGenerator::TYPE_NULL), ' public const FOO = null;'],
121+
[
122+
new PropertyValueGenerator('PHP_EOL', PropertyValueGenerator::TYPE_CONSTANT),
123+
' public const FOO = PHP_EOL;',
112124
],
113-
[new PropertyValueGenerator(true, PropertyValueGenerator::TYPE_BOOL), ' const FOO = true;'],
114-
[new PropertyValueGenerator(true, PropertyValueGenerator::TYPE_BOOLEAN), ' const FOO = true;'],
115-
[new PropertyValueGenerator(1, PropertyValueGenerator::TYPE_INT), ' const FOO = 1;'],
116-
[new PropertyValueGenerator(1, PropertyValueGenerator::TYPE_INTEGER), ' const FOO = 1;'],
117-
[new PropertyValueGenerator(0.1, PropertyValueGenerator::TYPE_DOUBLE), ' const FOO = 0.1;'],
118-
[new PropertyValueGenerator(0.1, PropertyValueGenerator::TYPE_FLOAT), ' const FOO = 0.1;'],
119-
[new PropertyValueGenerator('bar', PropertyValueGenerator::TYPE_STRING), " const FOO = 'bar';"],
120-
[new PropertyValueGenerator(null, PropertyValueGenerator::TYPE_NULL), ' const FOO = null;'],
121-
[new PropertyValueGenerator('PHP_EOL', PropertyValueGenerator::TYPE_CONSTANT), ' const FOO = PHP_EOL;'],
122125
];
123126
}
124127

test/TestAsset/BarClass.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
abstract class BarClass
1111
{
12-
const BAR = 5;
13-
const FOO = self::BAR;
12+
public const BAR = 5;
13+
public const FOO = self::BAR;
1414

1515
protected static $bar = 'value';
1616

test/TestAsset/FooClass.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
abstract class FooClass implements \ArrayAccess, E\Blarg, Local\SubClass
1212
{
13-
const BAR = 5;
14-
const FOO = self::BAR;
13+
public const BAR = 5;
14+
public const FOO = self::BAR;
1515

1616
/**
1717
* Constant comment

test/TestAsset/FooInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
interface FooInterface extends \ArrayAccess
1313
{
14-
const BAR = 5;
15-
const FOO = self::BAR;
14+
public const BAR = 5;
15+
public const FOO = self::BAR;
1616

1717
public function fooBarBaz();
1818

0 commit comments

Comments
 (0)