Skip to content

Commit 1b19132

Browse files
Merge remote-tracking branch '40114/introducing-generic-types-in-docblocks-for-improved-static-analysis' into sept-comprs
2 parents 00844ad + b6063ba commit 1b19132

File tree

6 files changed

+84
-41
lines changed

6 files changed

+84
-41
lines changed

app/code/Magento/ProductAlert/Helper/Data.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ public function getSaveUrl($type)
110110
/**
111111
* Create block instance
112112
*
113-
* @param string|\Magento\Framework\View\Element\AbstractBlock $block
114-
* @return \Magento\Framework\View\Element\AbstractBlock
113+
* @template T of \Magento\Framework\View\Element\AbstractBlock
114+
*
115+
* @param class-string<T>|T $block
116+
*
117+
* @return T
118+
*
115119
* @throws \Magento\Framework\Exception\LocalizedException
116120
*/
117121
public function createBlock($block)

lib/internal/Magento/Framework/View/Element/BlockFactory.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\View\Element;
77

@@ -33,9 +33,13 @@ public function __construct(ObjectManagerInterface $objectManager)
3333
/**
3434
* Create block
3535
*
36-
* @param string $blockName
36+
* @template T of BlockInterface
37+
*
38+
* @param class-string<T> $blockName
3739
* @param array $arguments
38-
* @return \Magento\Framework\View\Element\BlockInterface
40+
*
41+
* @return T
42+
*
3943
* @throws \LogicException
4044
*/
4145
public function createBlock($blockName, array $arguments = [])

lib/internal/Magento/Framework/View/Layout.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra
176176
protected $appState;
177177

178178
/**
179-
* @var \Psr\Log\LoggerInterface
179+
* @var Logger
180180
*/
181181
protected $logger;
182182

@@ -205,8 +205,8 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra
205205
* @param FrontendInterface $cache
206206
* @param ContextFactory $readerContextFactory
207207
* @param Layout\Generator\ContextFactory $generatorContextFactory
208-
* @param State $appState
209-
* @param LoggerInterface $logger
208+
* @param AppState $appState
209+
* @param Logger $logger
210210
* @param bool $cacheable
211211
* @param SerializerInterface|null $serializer
212212
* @param int|null $cacheLifetime
@@ -814,45 +814,56 @@ public function unsetElement($name)
814814
/**
815815
* Block Factory
816816
*
817-
* @param string $type
817+
* @template T of \Magento\Framework\View\Element\AbstractBlock
818+
*
819+
* @param class-string<T> $type
818820
* @param string $name
819821
* @param array $arguments
820-
* @return \Magento\Framework\View\Element\AbstractBlock
822+
*
823+
* @return T
821824
*/
822825
public function createBlock($type, $name = '', array $arguments = [])
823826
{
824827
$this->build();
825828
$name = $this->structure->createStructuralElement($name, Element::TYPE_BLOCK, $type);
826829
$block = $this->_createBlock($type, $name, $arguments);
827830
$block->setLayout($this);
831+
828832
return $block;
829833
}
830834

831835
/**
832836
* Create block and add to layout
833837
*
834-
* @param string $type
838+
* @template T of \Magento\Framework\View\Element\AbstractBlock
839+
*
840+
* @param class-string<T> $type
835841
* @param string $name
836842
* @param array $arguments
837-
* @return \Magento\Framework\View\Element\AbstractBlock
843+
*
844+
* @return T
838845
*/
839846
protected function _createBlock($type, $name, array $arguments = [])
840847
{
841848
/** @var \Magento\Framework\View\Layout\Generator\Block $blockGenerator */
842849
$blockGenerator = $this->generatorPool->getGenerator(Layout\Generator\Block::TYPE);
843850
$block = $blockGenerator->createBlock($type, $name, $arguments);
844851
$this->setBlock($name, $block);
852+
845853
return $block;
846854
}
847855

848856
/**
849857
* Add a block to registry, create new object if needed
850858
*
851-
* @param string|\Magento\Framework\View\Element\AbstractBlock $block
859+
* @template T of \Magento\Framework\View\Element\AbstractBlock
860+
*
861+
* @param class-string<T>|T $block
852862
* @param string $name
853863
* @param string $parent
854864
* @param string $alias
855-
* @return \Magento\Framework\View\Element\AbstractBlock
865+
*
866+
* @return T
856867
*/
857868
public function addBlock($block, $name = '', $parent = '', $alias = '')
858869
{
@@ -1041,8 +1052,12 @@ public function getMessagesBlock()
10411052
/**
10421053
* Get block singleton
10431054
*
1044-
* @param string $type
1045-
* @return \Magento\Framework\App\Helper\AbstractHelper
1055+
* @template T of \Magento\Framework\View\Element\AbstractBlock
1056+
*
1057+
* @param class-string<T> $type
1058+
*
1059+
* @return T
1060+
*
10461061
* @throws \Magento\Framework\Exception\LocalizedException
10471062
*/
10481063
public function getBlockSingleton($type)
@@ -1115,7 +1130,7 @@ public function executeRenderer($namespace, $staticType, $dynamicType, $data = [
11151130
$this->build();
11161131
if ($options = $this->getRendererOptions($namespace, $staticType, $dynamicType)) {
11171132
$dictionary = [];
1118-
/** @var $block \Magento\Framework\View\Element\Template */
1133+
/** @var \Magento\Framework\View\Element\Template $block */
11191134
$block = $this->createBlock($options['type'], '')
11201135
->setData($data)
11211136
->assign($dictionary)

lib/internal/Magento/Framework/View/Layout/Generator/Block.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\View\Layout\Generator;
77

@@ -20,7 +20,7 @@ class Block implements Layout\GeneratorInterface
2020
/**
2121
* Type of generator
2222
*/
23-
const TYPE = 'block';
23+
public const TYPE = 'block';
2424

2525
/**
2626
* @var \Magento\Framework\View\Element\BlockFactory
@@ -123,7 +123,7 @@ public function process(Layout\Reader\Context $readerContext, Layout\Generator\C
123123
$scheduledStructure = $readerContext->getScheduledStructure();
124124
$layout = $generatorContext->getLayout();
125125
$structure = $generatorContext->getStructure();
126-
/** @var $blocks \Magento\Framework\View\Element\AbstractBlock[] */
126+
/** @var \Magento\Framework\View\Element\AbstractBlock[] $blocks */
127127
$blocks = [];
128128
$blockActions = [];
129129
// Instantiate blocks and collect all actions data
@@ -242,10 +242,13 @@ protected function generateBlock(
242242
/**
243243
* Create block instance
244244
*
245-
* @param string|\Magento\Framework\View\Element\AbstractBlock $block
245+
* @template T of \Magento\Framework\View\Element\AbstractBlock
246+
*
247+
* @param class-string<T>|T $block
246248
* @param string $name
247249
* @param array $arguments
248-
* @return \Magento\Framework\View\Element\AbstractBlock
250+
*
251+
* @return T
249252
*/
250253
public function createBlock($block, $name, array $arguments = [])
251254
{
@@ -259,10 +262,14 @@ public function createBlock($block, $name, array $arguments = [])
259262
/**
260263
* Create block object instance based on block type
261264
*
262-
* @param string|\Magento\Framework\View\Element\AbstractBlock $block
265+
* @template T of \Magento\Framework\View\Element\AbstractBlock
266+
*
267+
* @param class-string<T>|T $block
263268
* @param array $arguments
269+
*
264270
* @throws \Magento\Framework\Exception\LocalizedException
265-
* @return \Magento\Framework\View\Element\AbstractBlock
271+
*
272+
* @return T
266273
*/
267274
protected function getBlockInstance($block, array $arguments = [])
268275
{

lib/internal/Magento/Framework/View/LayoutInterface.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\View;
77

@@ -187,21 +187,27 @@ public function getParentName($childName);
187187
/**
188188
* Block Factory
189189
*
190-
* @param string $type
191-
* @param string $name
192-
* @param array $arguments
193-
* @return Element\BlockInterface
190+
* @template T of Element\BlockInterface
191+
*
192+
* @param class-string<T> $type
193+
* @param string $name
194+
* @param array $arguments
195+
*
196+
* @return T
194197
*/
195198
public function createBlock($type, $name = '', array $arguments = []);
196199

197200
/**
198201
* Add a block to registry, create new object if needed
199202
*
200-
* @param string|\Magento\Framework\View\Element\AbstractBlock $block
203+
* @template T of Element\BlockInterface
204+
*
205+
* @param class-string<T>|T $block
201206
* @param string $name
202207
* @param string $parent
203208
* @param string $alias
204-
* @return Element\BlockInterface
209+
*
210+
* @return T
205211
*/
206212
public function addBlock($block, $name = '', $parent = '', $alias = '');
207213

@@ -252,8 +258,11 @@ public function getMessagesBlock();
252258
/**
253259
* Get block singleton
254260
*
255-
* @param string $type
256-
* @return Element\BlockInterface
261+
* @template T of Element\BlockInterface
262+
*
263+
* @param class-string<T> $type
264+
*
265+
* @return T
257266
*/
258267
public function getBlockSingleton($type);
259268

@@ -294,7 +303,7 @@ public function isManipulationAllowed($name);
294303
* Save block in blocks registry
295304
*
296305
* @param string $name
297-
* @param Element\BlockInterface $block
306+
* @param Element\BlockInterface $block
298307
* @return LayoutInterface
299308
*/
300309
public function setBlock($name, $block);

lib/internal/Magento/Framework/View/TemplateEngine/Php.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -121,8 +121,12 @@ public function __get($name)
121121
/**
122122
* Get helper singleton
123123
*
124-
* @param string $className
125-
* @return \Magento\Framework\App\Helper\AbstractHelper
124+
* @template T of \Magento\Framework\App\Helper\AbstractHelper
125+
*
126+
* @param class-string<T> $className
127+
*
128+
* @return T
129+
*
126130
* @throws \LogicException
127131
*/
128132
public function helper($className)

0 commit comments

Comments
 (0)