This is an automated email from the ASF dual-hosted git repository. tmysik pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new dd5c2d5c33 Fix PSR1Hint for Enum new db0e677e3e Merge pull request #5805 from junichi11/php-psr1-for-enum dd5c2d5c33 is described below commit dd5c2d5c3370d4418ce2c8b847f78b82d19efcac Author: Junichi Yamamoto <junich...@apache.org> AuthorDate: Mon Apr 10 23:38:22 2023 +0900 Fix PSR1Hint for Enum - Check the `EnumDeclaration` node - Add unit tests --- .../modules/php/editor/verification/PSR1Hint.java | 9 +++ .../PSR1/testConstantNameEnumNotOk_01/EnumName.php | 24 ++++++++ ...EnumName.php.testConstantNameEnumNotOk_01.hints | 4 ++ .../PSR1/testConstantNameEnumNotOk_02/EnumName.php | 25 +++++++++ ...EnumName.php.testConstantNameEnumNotOk_02.hints | 4 ++ .../PSR1/testConstantNameEnumNotOk_03/EnumName.php | 25 +++++++++ ...EnumName.php.testConstantNameEnumNotOk_03.hints | 4 ++ .../PSR1/testConstantNameEnumOk_01/EnumName.php | 25 +++++++++ .../EnumName.php.testConstantNameEnumOk_01.hints | 1 + .../PSR1/testConstantNameEnumOk_02/EnumName.php | 25 +++++++++ .../EnumName.php.testConstantNameEnumOk_02.hints | 1 + .../testEnumNameNotOkNamespace_01/EnumName.php | 22 ++++++++ ...numName.php.testEnumNameNotOkNamespace_01.hints | 4 ++ .../testEnumNameNotOkNamespace_02/EnumName.php | 24 ++++++++ ...numName.php.testEnumNameNotOkNamespace_02.hints | 4 ++ .../PSR1/testEnumNameNotOk_01/EnumName.php | 23 ++++++++ .../EnumName.php.testEnumNameNotOk_01.hints | 4 ++ .../PSR1/testEnumNameNotOk_02/EnumName.php | 23 ++++++++ .../EnumName.php.testEnumNameNotOk_02.hints | 4 ++ .../testEnumNameNotOneDeclaration_01/EnumName.php | 32 +++++++++++ ...Name.php.testEnumNameNotOneDeclaration_01.hints | 4 ++ .../PSR1/testEnumNameOk_01/EnumName.php | 23 ++++++++ .../EnumName.php.testEnumNameOk_01.hints | 1 + .../PSR1/testMethodEnumNotOk_01/EnumName.php | 28 ++++++++++ .../EnumName.php.testMethodEnumNotOk_01.hints | 4 ++ .../PSR1/testMethodEnumNotOk_02/EnumName.php | 26 +++++++++ .../EnumName.php.testMethodEnumNotOk_02.hints | 4 ++ .../PSR1/testMethodEnumOk_01/EnumName.php | 26 +++++++++ .../EnumName.php.testMethodEnumOk_01.hints | 1 + .../PSR1/testMethodEnumOk_02/EnumName.php | 26 +++++++++ .../EnumName.php.testMethodEnumOk_02.hints | 1 + .../PSR1/testSideEffect_11/EnumName.php | 26 +++++++++ .../EnumName.php.testSideEffect_11.hints | 4 ++ .../php/editor/verification/PSR1HintTest.java | 64 ++++++++++++++++++++++ 34 files changed, 525 insertions(+) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR1Hint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR1Hint.java index 4d51dbef17..9071a2ae8e 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR1Hint.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR1Hint.java @@ -34,6 +34,7 @@ import org.netbeans.modules.php.editor.parser.astnodes.Block; import org.netbeans.modules.php.editor.parser.astnodes.ClassDeclaration; import org.netbeans.modules.php.editor.parser.astnodes.ConstantDeclaration; import org.netbeans.modules.php.editor.parser.astnodes.EmptyStatement; +import org.netbeans.modules.php.editor.parser.astnodes.EnumDeclaration; import org.netbeans.modules.php.editor.parser.astnodes.FieldAccess; import org.netbeans.modules.php.editor.parser.astnodes.FunctionDeclaration; import org.netbeans.modules.php.editor.parser.astnodes.Identifier; @@ -239,6 +240,14 @@ public abstract class PSR1Hint extends HintRule { processTypeDeclaration(node); } + @Override + public void visit(EnumDeclaration node) { + if (CancelSupport.getDefault().isCancelled()) { + return; + } + processTypeDeclaration(node); + } + @NbBundle.Messages("PSR1TypeDeclarationMoreTypesHintText=Each type MUST be in a file by itself.") private void processTypeDeclaration(TypeDeclaration node) { Identifier typeNameNode = node.getName(); diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_01/EnumName.php new file mode 100644 index 0000000000..0918ba79d2 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_01/EnumName.php @@ -0,0 +1,24 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + + const foo_bar = 1; + case Case1; +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_01/EnumName.php.testConstantNameEnumNotOk_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_01/EnumName.php.testConstantNameEnumNotOk_01.hints new file mode 100644 index 0000000000..92080a4af2 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_01/EnumName.php.testConstantNameEnumNotOk_01.hints @@ -0,0 +1,4 @@ + const foo_bar = 1; + ------- +HINT:PSR-1 Violation: +Class constants MUST be declared in all upper case with underscore separators. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_02/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_02/EnumName.php new file mode 100644 index 0000000000..74577a878f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_02/EnumName.php @@ -0,0 +1,25 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + + const _BAR = 1; + case Case1; + +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_02/EnumName.php.testConstantNameEnumNotOk_02.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_02/EnumName.php.testConstantNameEnumNotOk_02.hints new file mode 100644 index 0000000000..5d9db12757 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_02/EnumName.php.testConstantNameEnumNotOk_02.hints @@ -0,0 +1,4 @@ + const _BAR = 1; + ---- +HINT:PSR-1 Violation: +Class constants MUST be declared in all upper case with underscore separators. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_03/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_03/EnumName.php new file mode 100644 index 0000000000..597fc7ebb0 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_03/EnumName.php @@ -0,0 +1,25 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + + const foobar = 1; + case Case1; + +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_03/EnumName.php.testConstantNameEnumNotOk_03.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_03/EnumName.php.testConstantNameEnumNotOk_03.hints new file mode 100644 index 0000000000..249101b47d --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumNotOk_03/EnumName.php.testConstantNameEnumNotOk_03.hints @@ -0,0 +1,4 @@ + const foobar = 1; + ------ +HINT:PSR-1 Violation: +Class constants MUST be declared in all upper case with underscore separators. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_01/EnumName.php new file mode 100644 index 0000000000..85dd4eec98 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_01/EnumName.php @@ -0,0 +1,25 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + + const FOO_BAR = 1; + case Case1; + +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_01/EnumName.php.testConstantNameEnumOk_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_01/EnumName.php.testConstantNameEnumOk_01.hints new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_01/EnumName.php.testConstantNameEnumOk_01.hints @@ -0,0 +1 @@ + diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_02/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_02/EnumName.php new file mode 100644 index 0000000000..5da2184f37 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_02/EnumName.php @@ -0,0 +1,25 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + + const FOOBAR = 1; + case Case1; + +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_02/EnumName.php.testConstantNameEnumOk_02.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_02/EnumName.php.testConstantNameEnumOk_02.hints new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testConstantNameEnumOk_02/EnumName.php.testConstantNameEnumOk_02.hints @@ -0,0 +1 @@ + diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_01/EnumName.php new file mode 100644 index 0000000000..2c5d08186b --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_01/EnumName.php @@ -0,0 +1,22 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + case Case1; +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_01/EnumName.php.testEnumNameNotOkNamespace_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_01/EnumName.php.testEnumNameNotOkNamespace_01.hints new file mode 100644 index 0000000000..ca2dc286a4 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_01/EnumName.php.testEnumNameNotOkNamespace_01.hints @@ -0,0 +1,4 @@ +enum EnumName { + -------- +HINT:PSR-1 Violation: +Each type MUST be in a namespace of at least one level: a top-level vendor name. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_02/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_02/EnumName.php new file mode 100644 index 0000000000..5b82601d5a --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_02/EnumName.php @@ -0,0 +1,24 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +namespace { + enum EnumName { + case Case1; + } +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_02/EnumName.php.testEnumNameNotOkNamespace_02.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_02/EnumName.php.testEnumNameNotOkNamespace_02.hints new file mode 100644 index 0000000000..f959303f9e --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOkNamespace_02/EnumName.php.testEnumNameNotOkNamespace_02.hints @@ -0,0 +1,4 @@ + enum EnumName { + -------- +HINT:PSR-1 Violation: +Each type MUST be in a namespace of at least one level: a top-level vendor name. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_01/EnumName.php new file mode 100644 index 0000000000..3ecae7729f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_01/EnumName.php @@ -0,0 +1,23 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +namespace Vendor; +enum Enum_Name { + case Case1; +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_01/EnumName.php.testEnumNameNotOk_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_01/EnumName.php.testEnumNameNotOk_01.hints new file mode 100644 index 0000000000..595c086ae0 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_01/EnumName.php.testEnumNameNotOk_01.hints @@ -0,0 +1,4 @@ +enum Enum_Name { + --------- +HINT:PSR-1 Violation: +Type names MUST be declared in StudlyCaps. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_02/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_02/EnumName.php new file mode 100644 index 0000000000..d62e219e80 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_02/EnumName.php @@ -0,0 +1,23 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +namespace Vendor; +enum enumName { + case Case1; +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_02/EnumName.php.testEnumNameNotOk_02.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_02/EnumName.php.testEnumNameNotOk_02.hints new file mode 100644 index 0000000000..fe796784fc --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOk_02/EnumName.php.testEnumNameNotOk_02.hints @@ -0,0 +1,4 @@ +enum enumName { + -------- +HINT:PSR-1 Violation: +Type names MUST be declared in StudlyCaps. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOneDeclaration_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOneDeclaration_01/EnumName.php new file mode 100644 index 0000000000..03b66c9aa5 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOneDeclaration_01/EnumName.php @@ -0,0 +1,32 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +namespace Vendor; + +enum Test { + + case Case1; + +} + +enum EnumName { + + case Case1; + +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOneDeclaration_01/EnumName.php.testEnumNameNotOneDeclaration_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOneDeclaration_01/EnumName.php.testEnumNameNotOneDeclaration_01.hints new file mode 100644 index 0000000000..e0d037370b --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameNotOneDeclaration_01/EnumName.php.testEnumNameNotOneDeclaration_01.hints @@ -0,0 +1,4 @@ +enum EnumName { + -------- +HINT:PSR-1 Violation: +Each type MUST be in a file by itself. diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameOk_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameOk_01/EnumName.php new file mode 100644 index 0000000000..7173def6e1 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameOk_01/EnumName.php @@ -0,0 +1,23 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +namespace Vendor; +enum EnumName { + case Case1; +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameOk_01/EnumName.php.testEnumNameOk_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameOk_01/EnumName.php.testEnumNameOk_01.hints new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testEnumNameOk_01/EnumName.php.testEnumNameOk_01.hints @@ -0,0 +1 @@ + diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_01/EnumName.php new file mode 100644 index 0000000000..8c0f0dbc4f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_01/EnumName.php @@ -0,0 +1,28 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + + case Case1; + + function foo_bar() { + + } + +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_01/EnumName.php.testMethodEnumNotOk_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_01/EnumName.php.testMethodEnumNotOk_01.hints new file mode 100644 index 0000000000..7c5983be52 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_01/EnumName.php.testMethodEnumNotOk_01.hints @@ -0,0 +1,4 @@ + function foo_bar() { + ------- +HINT:PSR-1 Violation: +Method names MUST be declared in camelCase(). diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_02/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_02/EnumName.php new file mode 100644 index 0000000000..f10bfa31e7 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_02/EnumName.php @@ -0,0 +1,26 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + case Case1; + + function FooBar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_02/EnumName.php.testMethodEnumNotOk_02.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_02/EnumName.php.testMethodEnumNotOk_02.hints new file mode 100644 index 0000000000..88f952cd02 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumNotOk_02/EnumName.php.testMethodEnumNotOk_02.hints @@ -0,0 +1,4 @@ + function FooBar() { + ------ +HINT:PSR-1 Violation: +Method names MUST be declared in camelCase(). diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_01/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_01/EnumName.php new file mode 100644 index 0000000000..528cca404f --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_01/EnumName.php @@ -0,0 +1,26 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + case Case1; + + function fooBar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_01/EnumName.php.testMethodEnumOk_01.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_01/EnumName.php.testMethodEnumOk_01.hints new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_01/EnumName.php.testMethodEnumOk_01.hints @@ -0,0 +1 @@ + diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_02/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_02/EnumName.php new file mode 100644 index 0000000000..081b3de642 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_02/EnumName.php @@ -0,0 +1,26 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +enum EnumName { + case Case1; + + function foobar() { + + } +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_02/EnumName.php.testMethodEnumOk_02.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_02/EnumName.php.testMethodEnumOk_02.hints new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testMethodEnumOk_02/EnumName.php.testMethodEnumOk_02.hints @@ -0,0 +1 @@ + diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testSideEffect_11/EnumName.php b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testSideEffect_11/EnumName.php new file mode 100644 index 0000000000..09a19d61ea --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testSideEffect_11/EnumName.php @@ -0,0 +1,26 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +if (true) { + require_once ''; +} else { + enum EnumName { + case Case1; + } +} diff --git a/php/php.editor/test/unit/data/testfiles/verification/PSR1/testSideEffect_11/EnumName.php.testSideEffect_11.hints b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testSideEffect_11/EnumName.php.testSideEffect_11.hints new file mode 100644 index 0000000000..9b73551cc6 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/PSR1/testSideEffect_11/EnumName.php.testSideEffect_11.hints @@ -0,0 +1,4 @@ + require_once ''; + ---------------- +HINT:PSR-1 Violation: +A file SHOULD declare new symbols and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both. diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/PSR1HintTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/PSR1HintTest.java index 39af112953..77c0d5142b 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/PSR1HintTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/PSR1HintTest.java @@ -43,6 +43,10 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "ClassName.php"); } + public void testEnumNameOk_01() throws Exception { + checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "EnumName.php"); + } + public void testTypeNameNotOk53() throws Exception { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "ClassName.php"); } @@ -51,6 +55,14 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "ClassName.php"); } + public void testEnumNameNotOk_01() throws Exception { + checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "EnumName.php"); + } + + public void testEnumNameNotOk_02() throws Exception { + checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "EnumName.php"); + } + public void testTypeNameOk52() throws Exception { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_52), "ClassName.php"); } @@ -71,6 +83,14 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "ClassName.php"); } + public void testEnumNameNotOkNamespace_01() throws Exception { + checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "EnumName.php"); + } + + public void testEnumNameNotOkNamespace_02() throws Exception { + checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "EnumName.php"); + } + public void testTypeNameNotOneDeclaration52() throws Exception { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_52), "ClassName.php"); } @@ -79,6 +99,10 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "ClassName.php"); } + public void testEnumNameNotOneDeclaration_01() throws Exception { + checkHints(new TypeDeclarationHintStub(PhpVersion.PHP_53), "EnumName.php"); + } + public void testConstantNameOk_1() throws Exception { checkHints(new PSR1Hint.ConstantDeclarationHint(), "ClassName.php"); } @@ -87,6 +111,14 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new PSR1Hint.ConstantDeclarationHint(), "ClassName.php"); } + public void testConstantNameEnumOk_01() throws Exception { + checkHints(new PSR1Hint.ConstantDeclarationHint(), "EnumName.php"); + } + + public void testConstantNameEnumOk_02() throws Exception { + checkHints(new PSR1Hint.ConstantDeclarationHint(), "EnumName.php"); + } + public void testConstantNameNotOk_1() throws Exception { checkHints(new PSR1Hint.ConstantDeclarationHint(), "ClassName.php"); } @@ -99,6 +131,18 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new PSR1Hint.ConstantDeclarationHint(), "ClassName.php"); } + public void testConstantNameEnumNotOk_01() throws Exception { + checkHints(new PSR1Hint.ConstantDeclarationHint(), "EnumName.php"); + } + + public void testConstantNameEnumNotOk_02() throws Exception { + checkHints(new PSR1Hint.ConstantDeclarationHint(), "EnumName.php"); + } + + public void testConstantNameEnumNotOk_03() throws Exception { + checkHints(new PSR1Hint.ConstantDeclarationHint(), "EnumName.php"); + } + public void testMethodOk_1() throws Exception { checkHints(new PSR1Hint.MethodDeclarationHint(), "ClassName.php"); } @@ -111,6 +155,14 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new PSR1Hint.MethodDeclarationHint(), "ClassName.php"); } + public void testMethodEnumOk_01() throws Exception { + checkHints(new PSR1Hint.MethodDeclarationHint(), "EnumName.php"); + } + + public void testMethodEnumOk_02() throws Exception { + checkHints(new PSR1Hint.MethodDeclarationHint(), "EnumName.php"); + } + public void testMethodNotOk_1() throws Exception { checkHints(new PSR1Hint.MethodDeclarationHint(), "ClassName.php"); } @@ -119,6 +171,14 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new PSR1Hint.MethodDeclarationHint(), "ClassName.php"); } + public void testMethodEnumNotOk_01() throws Exception { + checkHints(new PSR1Hint.MethodDeclarationHint(), "EnumName.php"); + } + + public void testMethodEnumNotOk_02() throws Exception { + checkHints(new PSR1Hint.MethodDeclarationHint(), "EnumName.php"); + } + public void testMethodMagicOk() throws Exception { checkHints(new PSR1Hint.MethodDeclarationHint(), "ClassName.php"); } @@ -187,6 +247,10 @@ public class PSR1HintTest extends PHPHintsTestBase { checkHints(new PSR1Hint.SideEffectHint(), "ClassName.php"); } + public void testSideEffect_11() throws Exception { + checkHints(new PSR1Hint.SideEffectHint(), "EnumName.php"); + } + @Override protected void checkHints(Rule hint, String fileName) throws Exception { super.checkHints(hint, getTestDir() + "/" + fileName); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists