@vituum/vite-plugin-latte 2.0.0-next.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/README.md +1 -1
  2. package/index.js +2 -1
  3. package/package.json +10 -9
  4. package/vendor/composer/autoload_classmap.php +3 -2
  5. package/vendor/composer/autoload_static.php +3 -2
  6. package/vendor/composer/installed.json +21 -17
  7. package/vendor/composer/installed.php +8 -8
  8. package/vendor/latte/latte/composer.json +9 -2
  9. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +7 -7
  10. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +5 -4
  11. package/vendor/latte/latte/src/Bridges/Tracy/TracyExtension.php +2 -4
  12. package/vendor/latte/latte/src/Bridges/Tracy/dist/panel.phtml +2 -4
  13. package/vendor/latte/latte/src/Bridges/Tracy/dist/tab.phtml +2 -4
  14. package/vendor/latte/latte/src/Latte/Compiler/Block.php +1 -3
  15. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +4 -8
  16. package/vendor/latte/latte/src/Latte/Compiler/Node.php +6 -3
  17. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +15 -6
  18. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +14 -9
  19. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +7 -3
  20. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +4 -3
  21. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +5 -4
  22. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +6 -5
  23. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +4 -6
  24. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +4 -3
  25. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +5 -7
  26. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ExpressionAttributeNode.php +6 -4
  27. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/TagNode.php +1 -3
  28. package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +4 -3
  29. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +4 -3
  30. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php +4 -3
  31. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ClosureUseNode.php +4 -3
  32. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +4 -3
  33. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +4 -3
  34. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +4 -3
  35. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +4 -3
  36. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +5 -4
  37. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +4 -3
  38. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +5 -4
  39. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +4 -3
  40. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +4 -3
  41. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +4 -3
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +7 -6
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +5 -4
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +4 -3
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +4 -3
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +4 -3
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InNode.php +4 -3
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +4 -3
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +4 -3
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +4 -3
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +4 -3
  52. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +4 -3
  53. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +4 -3
  54. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +4 -3
  55. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +4 -3
  56. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticMethodCallNode.php +4 -3
  57. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +4 -3
  58. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TemporaryNode.php +7 -6
  59. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +4 -3
  60. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +4 -3
  61. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +4 -3
  62. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +4 -3
  63. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +4 -3
  64. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +4 -3
  65. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/InterpolatedStringPartNode.php +4 -3
  66. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +4 -3
  67. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListItemNode.php +4 -3
  68. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListNode.php +4 -3
  69. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +4 -3
  70. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +4 -3
  71. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +4 -3
  72. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +4 -3
  73. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/OperatorNode.php +1 -3
  74. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +4 -3
  75. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +4 -3
  76. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +5 -4
  77. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +5 -4
  78. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +6 -5
  79. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +4 -3
  80. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +5 -4
  81. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +4 -3
  82. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +4 -3
  83. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +4 -3
  84. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +4 -3
  85. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VariadicPlaceholderNode.php +4 -3
  86. package/vendor/latte/latte/src/Latte/Compiler/Nodes/PrintNode.php +3 -4
  87. package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +7 -3
  88. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +4 -3
  89. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +5 -4
  90. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +23 -15
  91. package/vendor/latte/latte/src/Latte/Compiler/Position.php +5 -7
  92. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +30 -9
  93. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +6 -6
  94. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +4 -6
  95. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +14 -11
  96. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +2 -4
  97. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +13 -11
  98. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +21 -7
  99. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +32 -19
  100. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +28 -21
  101. package/vendor/latte/latte/src/Latte/Compiler/Token.php +10 -9
  102. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +20 -14
  103. package/vendor/latte/latte/src/Latte/ContentType.php +4 -3
  104. package/vendor/latte/latte/src/Latte/Engine.php +64 -35
  105. package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +3 -7
  106. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +4 -5
  107. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +2 -3
  108. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +1 -3
  109. package/vendor/latte/latte/src/Latte/Essential/Filters.php +65 -32
  110. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +8 -6
  111. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +5 -6
  112. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +3 -4
  113. package/vendor/latte/latte/src/Latte/Essential/Nodes/CustomFunctionCallNode.php +2 -4
  114. package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +2 -3
  115. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +6 -6
  116. package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +3 -4
  117. package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +2 -3
  118. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +3 -5
  119. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +3 -5
  120. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +4 -7
  121. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +3 -5
  122. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +7 -8
  123. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +4 -5
  124. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +7 -6
  125. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +6 -9
  126. package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +3 -4
  127. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +8 -7
  128. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +2 -4
  129. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +6 -6
  130. package/vendor/latte/latte/src/Latte/Essential/Nodes/JumpNode.php +4 -8
  131. package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +3 -5
  132. package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +3 -4
  133. package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +8 -5
  134. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +4 -4
  135. package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +4 -4
  136. package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +2 -4
  137. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +2 -3
  138. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +4 -5
  139. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +9 -7
  140. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +3 -4
  141. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +3 -4
  142. package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +2 -3
  143. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +3 -4
  144. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +4 -5
  145. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +8 -7
  146. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +2 -3
  147. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +3 -4
  148. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +5 -5
  149. package/vendor/latte/latte/src/Latte/Essential/Passes.php +26 -15
  150. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +1 -3
  151. package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +1 -3
  152. package/vendor/latte/latte/src/Latte/Essential/Tracer.php +20 -13
  153. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +9 -10
  154. package/vendor/latte/latte/src/Latte/Extension.php +10 -6
  155. package/vendor/latte/latte/src/Latte/Feature.php +24 -0
  156. package/vendor/latte/latte/src/Latte/Helpers.php +18 -10
  157. package/vendor/latte/latte/src/Latte/Loader.php +1 -3
  158. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +8 -5
  159. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +5 -13
  160. package/vendor/latte/latte/src/Latte/Policy.php +4 -3
  161. package/vendor/latte/latte/src/Latte/Runtime/Block.php +2 -4
  162. package/vendor/latte/latte/src/Latte/{Cache.php → Runtime/Cache.php} +12 -11
  163. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +3 -5
  164. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +10 -11
  165. package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +4 -6
  166. package/vendor/latte/latte/src/Latte/Runtime/Helpers.php +5 -7
  167. package/vendor/latte/latte/src/Latte/Runtime/Html.php +3 -5
  168. package/vendor/latte/latte/src/Latte/Runtime/HtmlHelpers.php +18 -18
  169. package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +1 -3
  170. package/vendor/latte/latte/src/Latte/Runtime/Template.php +23 -42
  171. package/vendor/latte/latte/src/Latte/Runtime/XmlHelpers.php +5 -7
  172. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +14 -8
  173. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +17 -11
  174. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +4 -3
  175. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +3 -4
  176. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallNode.php +16 -10
  177. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +4 -3
  178. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +6 -5
  179. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +5 -4
  180. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +17 -16
  181. package/vendor/latte/latte/src/Latte/attributes.php +7 -3
  182. package/vendor/latte/latte/src/Latte/exceptions.php +38 -3
  183. package/vendor/latte/latte/src/Tools/Linter.php +20 -14
  184. package/vendor/latte/latte/src/Tools/LinterExtension.php +26 -7
  185. package/vendor/nette/utils/composer.json +8 -1
  186. package/vendor/nette/utils/src/HtmlStringable.php +4 -1
  187. package/vendor/nette/utils/src/Iterators/CachingIterator.php +9 -24
  188. package/vendor/nette/utils/src/Iterators/Mapper.php +2 -3
  189. package/vendor/nette/utils/src/SmartObject.php +3 -0
  190. package/vendor/nette/utils/src/StaticClass.php +1 -1
  191. package/vendor/nette/utils/src/Translator.php +1 -1
  192. package/vendor/nette/utils/src/Utils/ArrayHash.php +1 -5
  193. package/vendor/nette/utils/src/Utils/ArrayList.php +3 -6
  194. package/vendor/nette/utils/src/Utils/Arrays.php +33 -10
  195. package/vendor/nette/utils/src/Utils/Callback.php +12 -7
  196. package/vendor/nette/utils/src/Utils/DateTime.php +1 -1
  197. package/vendor/nette/utils/src/Utils/FileInfo.php +5 -7
  198. package/vendor/nette/utils/src/Utils/FileSystem.php +5 -2
  199. package/vendor/nette/utils/src/Utils/Finder.php +27 -8
  200. package/vendor/nette/utils/src/Utils/Helpers.php +7 -1
  201. package/vendor/nette/utils/src/Utils/Html.php +123 -118
  202. package/vendor/nette/utils/src/Utils/Image.php +72 -54
  203. package/vendor/nette/utils/src/Utils/ImageColor.php +4 -0
  204. package/vendor/nette/utils/src/Utils/Iterables.php +16 -8
  205. package/vendor/nette/utils/src/Utils/Paginator.php +10 -43
  206. package/vendor/nette/utils/src/Utils/Reflection.php +17 -7
  207. package/vendor/nette/utils/src/Utils/ReflectionMethod.php +4 -1
  208. package/vendor/nette/utils/src/Utils/Strings.php +48 -15
  209. package/vendor/nette/utils/src/Utils/Type.php +41 -27
  210. package/vendor/nette/utils/src/Utils/Validators.php +8 -7
  211. package/vendor/latte/latte/src/Bridges/Tracy/panel.latte +0 -94
  212. package/vendor/latte/latte/src/Bridges/Tracy/tab.latte +0 -8
  213. package/vendor/latte/latte/src/Latte/PositionAwareException.php +0 -47
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte;
11
9
 
12
10
 
@@ -18,6 +16,43 @@ interface Exception
18
16
  }
19
17
 
20
18
 
19
+ /**
20
+ * @internal
21
+ */
22
+ trait PositionAwareException
23
+ {
24
+ public ?string $sourceCode = null;
25
+ public ?string $sourceName = null;
26
+ public ?Compiler\Position $position = null;
27
+ private string $origMessage;
28
+
29
+
30
+ public function setSource(string $code, ?string $name = null): self
31
+ {
32
+ $this->sourceCode = $code;
33
+ $this->sourceName = $name;
34
+ $this->generateMessage();
35
+ return $this;
36
+ }
37
+
38
+
39
+ private function generateMessage(): void
40
+ {
41
+ $this->origMessage ??= $this->message;
42
+ $info = [];
43
+ if ($this->sourceName && @is_file($this->sourceName)) { // @ - may trigger error
44
+ $info[] = "in '" . str_replace(dirname($this->sourceName, 2), '...', $this->sourceName) . "'";
45
+ }
46
+ if ($this->position) {
47
+ $info[] = $this->position;
48
+ }
49
+ $this->message = $info
50
+ ? rtrim($this->origMessage, '.') . ' (' . implode(' ', $info) . ')'
51
+ : $this->origMessage;
52
+ }
53
+ }
54
+
55
+
21
56
  /**
22
57
  * Template compilation failed.
23
58
  */
@@ -1,29 +1,31 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Tools;
11
9
 
12
10
  use Latte;
13
11
  use Nette;
14
12
  use function in_array, strlen;
15
- use const PHP_BINARY, STDERR;
13
+ use const DIRECTORY_SEPARATOR, PHP_BINARY, STDERR;
16
14
 
17
15
 
16
+ /**
17
+ * Validates Latte template syntax.
18
+ */
18
19
  final class Linter
19
20
  {
21
+ /** @var string[] */
20
22
  public array $excludedDirs = ['.*', '*.tmp', 'temp', 'vendor', 'node_modules'];
21
23
 
22
24
 
23
25
  public function __construct(
24
26
  private ?Latte\Engine $engine = null,
25
- private bool $debug = false,
26
- private bool $strict = false,
27
+ private readonly bool $debug = false,
28
+ private readonly bool $strict = false,
27
29
  ) {
28
30
  }
29
31
 
@@ -61,7 +63,7 @@ final class Linter
61
63
  {
62
64
  $engine = new Latte\Engine;
63
65
  $engine->enablePhpLinter(PHP_BINARY);
64
- $engine->setStrictParsing($this->strict);
66
+ $engine->setFeature(Latte\Feature::StrictParsing, $this->strict);
65
67
  $engine->addExtension(new Latte\Essential\TranslatorExtension(null));
66
68
 
67
69
  if (class_exists(Nette\Bridges\ApplicationLatte\UIExtension::class)) {
@@ -95,12 +97,12 @@ final class Linter
95
97
 
96
98
  public function lintLatte(string $file): bool
97
99
  {
98
- set_error_handler(function (int $severity, string $message) use ($file) {
99
- if (in_array($severity, [E_USER_DEPRECATED, E_USER_WARNING, E_USER_NOTICE], true)) {
100
+ set_error_handler(function (int $severity, string $message, string $errFile = '', int $errLine = 0) use ($file): bool {
101
+ if (in_array($severity, [E_USER_DEPRECATED, E_USER_WARNING, E_USER_NOTICE], strict: true)) {
100
102
  $pos = preg_match('~on line (\d+)~', $message, $m) ? ':' . $m[1] : '';
101
103
  $label = $severity === E_USER_DEPRECATED ? 'DEPRECATED' : 'WARNING';
102
104
  $this->writeError($label, $file . $pos, $message);
103
- return null;
105
+ return true;
104
106
  }
105
107
  return false;
106
108
  });
@@ -109,7 +111,11 @@ final class Linter
109
111
  echo $file, "\n";
110
112
  }
111
113
  $s = file_get_contents($file);
112
- if (substr($s, 0, 3) === "\xEF\xBB\xBF") {
114
+ if ($s === false) {
115
+ $this->writeError('ERROR', $file, 'unable to read file');
116
+ return false;
117
+ }
118
+ if (str_starts_with($s, "\xEF\xBB\xBF")) {
113
119
  $this->writeError('WARNING', $file, 'contains BOM');
114
120
  }
115
121
 
@@ -138,13 +144,13 @@ final class Linter
138
144
  private function initialize(): void
139
145
  {
140
146
  if (function_exists('pcntl_signal')) {
141
- pcntl_signal(SIGINT, function (): void {
147
+ pcntl_signal(SIGINT, function (): never {
142
148
  pcntl_signal(SIGINT, SIG_DFL);
143
149
  echo "Terminated\n";
144
150
  exit(1);
145
151
  });
146
152
  } elseif (function_exists('sapi_windows_set_ctrl_handler')) {
147
- sapi_windows_set_ctrl_handler(function () {
153
+ sapi_windows_set_ctrl_handler(function (): never {
148
154
  echo "Terminated\n";
149
155
  exit(1);
150
156
  });
@@ -159,7 +165,7 @@ final class Linter
159
165
  $it = match (true) {
160
166
  is_file($path) => new \ArrayIterator([$path]),
161
167
  is_dir($path) => $this->findLatteFiles($path),
162
- preg_match('~[*?]~', $path) => new \GlobIterator($path),
168
+ (bool) preg_match('~[*?]~', $path) => new \GlobIterator($path),
163
169
  default => throw new \InvalidArgumentException("File or directory '$path' not found."),
164
170
  };
165
171
  $it = new \CallbackFilterIterator($it, fn($file) => is_file((string) $file));
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Tools;
11
9
 
12
10
  use Latte;
@@ -50,7 +48,7 @@ final class LinterExtension extends Latte\Extension
50
48
  $this->validateFunction($node);
51
49
 
52
50
  } elseif ($node instanceof Expression\NewNode && $node->class instanceof Php\NameNode) {
53
- $this->validateClass($node);
51
+ $this->validateNewObject($node);
54
52
 
55
53
  } elseif ($node instanceof Expression\StaticMethodCallNode
56
54
  && $node->class instanceof Php\NameNode
@@ -62,7 +60,9 @@ final class LinterExtension extends Latte\Extension
62
60
  && $node->class instanceof Php\NameNode
63
61
  && $node->name instanceof Php\IdentifierNode
64
62
  ) {
65
- $this->validateClassConstant($node);
63
+ $node->name->name === 'class'
64
+ ? $this->validateClassType($node->class)
65
+ : $this->validateClassConstant($node);
66
66
 
67
67
  } elseif ($node instanceof Expression\ConstantFetchNode) {
68
68
  $this->validateConstant($node);
@@ -83,6 +83,7 @@ final class LinterExtension extends Latte\Extension
83
83
  private function validateFilter(Php\FilterNode $node): void
84
84
  {
85
85
  $name = $node->name->name;
86
+ assert($this->engine !== null);
86
87
  $filters = $this->engine->getFilters();
87
88
  if (!isset($filters[$name])) {
88
89
  trigger_error("Unknown filter |$name $node->position", E_USER_WARNING);
@@ -92,6 +93,7 @@ final class LinterExtension extends Latte\Extension
92
93
 
93
94
  private function validateFunction(Expression\FunctionCallNode $node): void
94
95
  {
96
+ assert($node->name instanceof Php\NameNode);
95
97
  $name = (string) $node->name;
96
98
  if (!function_exists($name)) {
97
99
  trigger_error("Unknown function $name() $node->position", E_USER_WARNING);
@@ -99,10 +101,11 @@ final class LinterExtension extends Latte\Extension
99
101
  }
100
102
 
101
103
 
102
- private function validateClass(Expression\NewNode $node): void
104
+ private function validateNewObject(Expression\NewNode $node): void
103
105
  {
106
+ assert($node->class instanceof Php\NameNode);
104
107
  $className = (string) $node->class;
105
- if (!class_exists($className) && !interface_exists($className)) {
108
+ if (!class_exists($className)) {
106
109
  trigger_error("Unknown class $className $node->position", E_USER_WARNING);
107
110
  }
108
111
  }
@@ -110,6 +113,8 @@ final class LinterExtension extends Latte\Extension
110
113
 
111
114
  private function validateStaticMethod(Expression\StaticMethodCallNode $node): void
112
115
  {
116
+ assert($node->class instanceof Php\NameNode);
117
+ assert($node->name instanceof Php\IdentifierNode);
113
118
  $className = (string) $node->class;
114
119
  $methodName = $node->name->name;
115
120
  if (!method_exists($className, $methodName)) {
@@ -118,8 +123,19 @@ final class LinterExtension extends Latte\Extension
118
123
  }
119
124
 
120
125
 
126
+ private function validateClassType(Php\NameNode $node): void
127
+ {
128
+ $className = (string) $node;
129
+ if (!class_exists($className) && !interface_exists($className) && !trait_exists($className)) {
130
+ trigger_error("Unknown class $className $node->position", E_USER_WARNING);
131
+ }
132
+ }
133
+
134
+
121
135
  private function validateClassConstant(Expression\ClassConstantFetchNode $node): void
122
136
  {
137
+ assert($node->class instanceof Php\NameNode);
138
+ assert($node->name instanceof Php\IdentifierNode);
123
139
  $name = "{$node->class}::{$node->name->name}";
124
140
  if (!defined($name)) {
125
141
  trigger_error("Unknown class constant $name $node->position", E_USER_WARNING);
@@ -139,6 +155,7 @@ final class LinterExtension extends Latte\Extension
139
155
 
140
156
  private function validateInstanceof(Expression\InstanceofNode $node): void
141
157
  {
158
+ assert($node->class instanceof Php\NameNode);
142
159
  $className = (string) $node->class;
143
160
  if (!class_exists($className) && !interface_exists($className)) {
144
161
  trigger_error("Unknown class $className in instanceof $node->position", E_USER_WARNING);
@@ -148,6 +165,8 @@ final class LinterExtension extends Latte\Extension
148
165
 
149
166
  private function validateStaticProperty(Expression\StaticPropertyFetchNode $node): void
150
167
  {
168
+ assert($node->class instanceof Php\NameNode);
169
+ assert($node->name instanceof Php\VarLikeIdentifierNode);
151
170
  $className = (string) $node->class;
152
171
  $propertyName = $node->name->name;
153
172
  if (!property_exists($className, $propertyName)) {
@@ -20,7 +20,9 @@
20
20
  "require-dev": {
21
21
  "nette/tester": "^2.5",
22
22
  "tracy/tracy": "^2.9",
23
- "phpstan/phpstan-nette": "^2.0@stable",
23
+ "phpstan/phpstan": "^2.1@stable",
24
+ "phpstan/extension-installer": "^1.4@stable",
25
+ "nette/phpstan-rules": "^1.0",
24
26
  "jetbrains/phpstorm-attributes": "^1.2"
25
27
  },
26
28
  "conflict": {
@@ -50,5 +52,10 @@
50
52
  "branch-alias": {
51
53
  "dev-master": "4.1-dev"
52
54
  }
55
+ },
56
+ "config": {
57
+ "allow-plugins": {
58
+ "phpstan/extension-installer": true
59
+ }
53
60
  }
54
61
  }
@@ -10,10 +10,13 @@ declare(strict_types=1);
10
10
  namespace Nette;
11
11
 
12
12
 
13
+ /**
14
+ * Represents object convertible to HTML string.
15
+ */
13
16
  interface HtmlStringable
14
17
  {
15
18
  /**
16
- * Returns string in HTML format
19
+ * Returns string in HTML format.
17
20
  */
18
21
  function __toString(): string;
19
22
  }
@@ -13,16 +13,19 @@ use Nette;
13
13
 
14
14
 
15
15
  /**
16
- * Smarter caching iterator.
16
+ * Enhanced caching iterator with first/last/counter tracking.
17
17
  *
18
+ * @template TKey
19
+ * @template TValue
20
+ * @extends \CachingIterator<TKey, TValue, \Iterator<TKey, TValue>>
18
21
  * @property-read bool $first
19
22
  * @property-read bool $last
20
23
  * @property-read bool $empty
21
24
  * @property-read bool $odd
22
25
  * @property-read bool $even
23
26
  * @property-read int $counter
24
- * @property-read mixed $nextKey
25
- * @property-read mixed $nextValue
27
+ * @property-read TKey $nextKey
28
+ * @property-read TValue $nextValue
26
29
  */
27
30
  class CachingIterator extends \CachingIterator implements \Countable
28
31
  {
@@ -31,6 +34,7 @@ class CachingIterator extends \CachingIterator implements \Countable
31
34
  private int $counter = 0;
32
35
 
33
36
 
37
+ /** @param iterable<TKey, TValue>|\stdClass $iterable */
34
38
  public function __construct(iterable|\stdClass $iterable)
35
39
  {
36
40
  $iterable = $iterable instanceof \stdClass
@@ -58,45 +62,30 @@ class CachingIterator extends \CachingIterator implements \Countable
58
62
  }
59
63
 
60
64
 
61
- /**
62
- * Is the iterator empty?
63
- */
64
65
  public function isEmpty(): bool
65
66
  {
66
67
  return $this->counter === 0;
67
68
  }
68
69
 
69
70
 
70
- /**
71
- * Is the counter odd?
72
- */
73
71
  public function isOdd(): bool
74
72
  {
75
73
  return $this->counter % 2 === 1;
76
74
  }
77
75
 
78
76
 
79
- /**
80
- * Is the counter even?
81
- */
82
77
  public function isEven(): bool
83
78
  {
84
79
  return $this->counter % 2 === 0;
85
80
  }
86
81
 
87
82
 
88
- /**
89
- * Returns the counter.
90
- */
91
83
  public function getCounter(): int
92
84
  {
93
85
  return $this->counter;
94
86
  }
95
87
 
96
88
 
97
- /**
98
- * Returns the count of elements.
99
- */
100
89
  public function count(): int
101
90
  {
102
91
  $inner = $this->getInnerIterator();
@@ -131,18 +120,14 @@ class CachingIterator extends \CachingIterator implements \Countable
131
120
  }
132
121
 
133
122
 
134
- /**
135
- * Returns the next key.
136
- */
123
+ /** @return TKey */
137
124
  public function getNextKey(): mixed
138
125
  {
139
126
  return $this->getInnerIterator()->key();
140
127
  }
141
128
 
142
129
 
143
- /**
144
- * Returns the next element.
145
- */
130
+ /** @return TValue */
146
131
  public function getNextValue(): mixed
147
132
  {
148
133
  return $this->getInnerIterator()->current();
@@ -15,14 +15,13 @@ namespace Nette\Iterators;
15
15
  */
16
16
  class Mapper extends \IteratorIterator
17
17
  {
18
- /** @var callable */
19
- private $callback;
18
+ private \Closure $callback;
20
19
 
21
20
 
22
21
  public function __construct(\Traversable $iterator, callable $callback)
23
22
  {
24
23
  parent::__construct($iterator);
25
- $this->callback = $callback;
24
+ $this->callback = $callback(...);
26
25
  }
27
26
 
28
27
 
@@ -22,6 +22,7 @@ use Nette\Utils\ObjectHelpers;
22
22
  trait SmartObject
23
23
  {
24
24
  /**
25
+ * @param mixed[] $args
25
26
  * @return mixed
26
27
  * @throws MemberAccessException
27
28
  */
@@ -47,6 +48,8 @@ trait SmartObject
47
48
 
48
49
 
49
50
  /**
51
+ * @param mixed[] $args
52
+ * @return never
50
53
  * @throws MemberAccessException
51
54
  */
52
55
  public static function __callStatic(string $name, array $args)
@@ -11,7 +11,7 @@ namespace Nette;
11
11
 
12
12
 
13
13
  /**
14
- * Static class.
14
+ * Prevents instantiation.
15
15
  */
16
16
  trait StaticClass
17
17
  {
@@ -11,7 +11,7 @@ namespace Nette\Localization;
11
11
 
12
12
 
13
13
  /**
14
- * Translator adapter.
14
+ * Translation provider.
15
15
  */
16
16
  interface Translator
17
17
  {
@@ -14,7 +14,7 @@ use function count, is_array, is_scalar, sprintf;
14
14
 
15
15
 
16
16
  /**
17
- * Provides objects to work as array.
17
+ * Array-like object with property access.
18
18
  * @template T
19
19
  * @implements \IteratorAggregate<array-key, T>
20
20
  * @implements \ArrayAccess<array-key, T>
@@ -39,7 +39,6 @@ class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \Iterator
39
39
 
40
40
 
41
41
  /**
42
- * Returns an iterator over all items.
43
42
  * @return \Iterator<array-key, T>
44
43
  */
45
44
  public function &getIterator(): \Iterator
@@ -50,9 +49,6 @@ class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \Iterator
50
49
  }
51
50
 
52
51
 
53
- /**
54
- * Returns items count.
55
- */
56
52
  public function count(): int
57
53
  {
58
54
  return count((array) $this);
@@ -14,13 +14,14 @@ use function array_slice, array_splice, count, is_int;
14
14
 
15
15
 
16
16
  /**
17
- * Provides the base class for a generic list (items can be accessed by index).
17
+ * Generic list with integer indices.
18
18
  * @template T
19
19
  * @implements \IteratorAggregate<int, T>
20
20
  * @implements \ArrayAccess<int, T>
21
21
  */
22
22
  class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
23
23
  {
24
+ /** @var list<T> */
24
25
  private array $list = [];
25
26
 
26
27
 
@@ -41,7 +42,6 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
41
42
 
42
43
 
43
44
  /**
44
- * Returns an iterator over all items.
45
45
  * @return \Iterator<int, T>
46
46
  */
47
47
  public function &getIterator(): \Iterator
@@ -52,9 +52,6 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
52
52
  }
53
53
 
54
54
 
55
- /**
56
- * Returns items count.
57
- */
58
55
  public function count(): int
59
56
  {
60
57
  return count($this->list);
@@ -63,7 +60,7 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
63
60
 
64
61
  /**
65
62
  * Replaces or appends an item.
66
- * @param int|null $index
63
+ * @param ?int $index
67
64
  * @param T $value
68
65
  * @throws Nette\OutOfRangeException
69
66
  */
@@ -79,7 +79,7 @@ class Arrays
79
79
  * @template T2
80
80
  * @param array<T1> $array1
81
81
  * @param array<T2> $array2
82
- * @return array<T1|T2>
82
+ * @return array<T1|T2|array<mixed>>
83
83
  */
84
84
  public static function mergeTree(array $array1, array $array2): array
85
85
  {
@@ -96,6 +96,7 @@ class Arrays
96
96
 
97
97
  /**
98
98
  * Returns zero-indexed position of given array key. Returns null if key is not found.
99
+ * @param array<mixed> $array
99
100
  */
100
101
  public static function getKeyOffset(array $array, string|int $key): ?int
101
102
  {
@@ -104,9 +105,10 @@ class Arrays
104
105
 
105
106
 
106
107
  /**
108
+ * @param array<mixed> $array
107
109
  * @deprecated use getKeyOffset()
108
110
  */
109
- public static function searchKey(array $array, $key): ?int
111
+ public static function searchKey(array $array, string|int $key): ?int
110
112
  {
111
113
  return self::getKeyOffset($array, $key);
112
114
  }
@@ -114,10 +116,11 @@ class Arrays
114
116
 
115
117
  /**
116
118
  * Tests an array for the presence of value.
119
+ * @param array<mixed> $array
117
120
  */
118
121
  public static function contains(array $array, mixed $value): bool
119
122
  {
120
- return in_array($value, $array, true);
123
+ return in_array($value, $array, strict: true);
121
124
  }
122
125
 
123
126
 
@@ -125,9 +128,11 @@ class Arrays
125
128
  * Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
126
129
  * @template K of int|string
127
130
  * @template V
131
+ * @template E
128
132
  * @param array<K, V> $array
129
133
  * @param ?callable(V, K, array<K, V>): bool $predicate
130
- * @return ?V
134
+ * @param ?callable(): E $else
135
+ * @return ($else is null ? ?V : V|E)
131
136
  */
132
137
  public static function first(array $array, ?callable $predicate = null, ?callable $else = null): mixed
133
138
  {
@@ -142,9 +147,11 @@ class Arrays
142
147
  * Returns the last item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
143
148
  * @template K of int|string
144
149
  * @template V
150
+ * @template E
145
151
  * @param array<K, V> $array
146
152
  * @param ?callable(V, K, array<K, V>): bool $predicate
147
- * @return ?V
153
+ * @param ?callable(): E $else
154
+ * @return ($else is null ? ?V : V|E)
148
155
  */
149
156
  public static function last(array $array, ?callable $predicate = null, ?callable $else = null): mixed
150
157
  {
@@ -196,6 +203,8 @@ class Arrays
196
203
  /**
197
204
  * Inserts the contents of the $inserted array into the $array immediately after the $key.
198
205
  * If $key is null (or does not exist), it is inserted at the beginning.
206
+ * @param array<mixed> $array
207
+ * @param array<mixed> $inserted
199
208
  */
200
209
  public static function insertBefore(array &$array, string|int|null $key, array $inserted): void
201
210
  {
@@ -209,6 +218,8 @@ class Arrays
209
218
  /**
210
219
  * Inserts the contents of the $inserted array into the $array before the $key.
211
220
  * If $key is null (or does not exist), it is inserted at the end.
221
+ * @param array<mixed> $array
222
+ * @param array<mixed> $inserted
212
223
  */
213
224
  public static function insertAfter(array &$array, string|int|null $key, array $inserted): void
214
225
  {
@@ -224,6 +235,7 @@ class Arrays
224
235
 
225
236
  /**
226
237
  * Renames key in array.
238
+ * @param array<mixed> $array
227
239
  */
228
240
  public static function renameKey(array &$array, string|int $oldKey, string|int $newKey): bool
229
241
  {
@@ -260,6 +272,8 @@ class Arrays
260
272
 
261
273
  /**
262
274
  * Transforms multidimensional array to flat array.
275
+ * @param array<mixed> $array
276
+ * @return array<mixed>
263
277
  */
264
278
  public static function flatten(array $array, bool $preserveKeys = false): array
265
279
  {
@@ -284,16 +298,18 @@ class Arrays
284
298
 
285
299
  /**
286
300
  * Reformats table to associative tree. Path looks like 'field|field[]field->field=field'.
287
- * @param string|string[] $path
301
+ * @param array<mixed> $array
302
+ * @param string|list<string> $path
303
+ * @return array<mixed>|\stdClass
288
304
  */
289
- public static function associate(array $array, $path): array|\stdClass
305
+ public static function associate(array $array, string|array $path): array|\stdClass
290
306
  {
291
307
  $parts = is_array($path)
292
308
  ? $path
293
309
  : preg_split('#(\[\]|->|=|\|)#', $path, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
294
310
 
295
311
  if (!$parts || $parts === ['->'] || $parts[0] === '=' || $parts[0] === '|') {
296
- throw new Nette\InvalidArgumentException("Invalid path '$path'.");
312
+ throw new Nette\InvalidArgumentException("Invalid path '" . (is_array($path) ? implode('', $path) : $path) . "'.");
297
313
  }
298
314
 
299
315
  $res = $parts[0] === '->' ? new \stdClass : [];
@@ -312,6 +328,8 @@ class Arrays
312
328
  $x = $row[$parts[$i]];
313
329
  $row = null;
314
330
  }
331
+ break; // '=' is always the final operation
332
+
315
333
  } elseif ($part === '->') {
316
334
  if (isset($parts[++$i])) {
317
335
  if ($x === null) {
@@ -338,6 +356,8 @@ class Arrays
338
356
 
339
357
  /**
340
358
  * Normalizes array to associative array. Replace numeric keys with their values, the new value will be $filling.
359
+ * @param array<mixed> $array
360
+ * @return array<string, mixed>
341
361
  */
342
362
  public static function normalize(array $array, mixed $filling = null): array
343
363
  {
@@ -481,8 +501,9 @@ class Arrays
481
501
  /**
482
502
  * Invokes all callbacks and returns array of results.
483
503
  * @param callable[] $callbacks
504
+ * @return array<mixed>
484
505
  */
485
- public static function invoke(iterable $callbacks, ...$args): array
506
+ public static function invoke(iterable $callbacks, mixed ...$args): array
486
507
  {
487
508
  $res = [];
488
509
  foreach ($callbacks as $k => $cb) {
@@ -496,8 +517,9 @@ class Arrays
496
517
  /**
497
518
  * Invokes method on every object in an array and returns array of results.
498
519
  * @param object[] $objects
520
+ * @return array<mixed>
499
521
  */
500
- public static function invokeMethod(iterable $objects, string $method, ...$args): array
522
+ public static function invokeMethod(iterable $objects, string $method, mixed ...$args): array
501
523
  {
502
524
  $res = [];
503
525
  foreach ($objects as $k => $obj) {
@@ -511,6 +533,7 @@ class Arrays
511
533
  /**
512
534
  * Copies the elements of the $array array to the $object object and then returns it.
513
535
  * @template T of object
536
+ * @param iterable<mixed> $array
514
537
  * @param T $object
515
538
  * @return T
516
539
  */