Skip to content

Commit 647ece8

Browse files
Merge pull request #3 from iodigital-com/feature/add-new-magento-stub-files
Add new Magento 2 stub files
2 parents f2d6aa2 + 27ebf5b commit 647ece8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+483
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PHPStan Magento 2 stubfiles
22

3-
[PHPStan](https://phpstan.org/) stubfiles for the Magento 2 framework. Currenly the stub files are targeted towards the 2.4.5-p1 version.
3+
[PHPStan](https://phpstan.org/) stubfiles for the Magento 2 framework. Currenly the stub files are targeted towards the 2.4.7.x version.
44

55
## Installation
66

@@ -12,5 +12,8 @@ If you use the [phpstan/extension-installer](https://github.com/phpstan/extensio
1212

1313
```yaml
1414
includes:
15-
- ./vendor/iodigital-com/phpstan-magento2-stubfiles/extension.yml
15+
- ./vendor/iodigital-com/phpstan-magento2-stubs/extension.neon
1616
```
17+
18+
## Notes
19+
It is not possible to replace @method in stubFiles since it will overwrite the complete phpdoc. This means you will have to copy all the @methods from that specific class. Please ignore this in your PHPStan Baseline.

extension.neon

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
11
parameters:
22
stubFiles:
33
- ./stubs/Magento/AdvancedSearch/Model/Adapter/DataMapper/AdditionalFieldsProviderInterface.stub
4+
- ./stubs/Magento/Bundle/Model/ResourceModel/Selection/Collection.stub
5+
- ./stubs/Magento/Catalog/Api/Data/ProductAttributeMediaGalleryEntryInterface.stub
6+
- ./stubs/Magento/Catalog/Api/Data/ProductCustomOptionValuesInterface.stub
47
- ./stubs/Magento/Catalog/Api/Data/ProductInterface.stub
8+
- ./stubs/Magento/Catalog/Model/Product.stub
9+
- ./stubs/Magento/Catalog/Model/Product/Option.stub
10+
- ./stubs/Magento/Catalog/Model/Product/Option/Repository.stub
11+
- ./stubs/Magento/Catalog/Model/Product/Option/Value.stub
12+
- ./stubs/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.stub
13+
- ./stubs/Magento/Catalog/Model/ResourceModel/Product/Collection.stub
14+
- ./stubs/Magento/Catalog/Model/ResourceModel/Product/CollectionFactory.stub
515
- ./stubs/Magento/Cms/Api/Data/PageInterface.stub
616
- ./stubs/Magento/Cms/Api/PageRepositoryInterface.stub
717
- ./stubs/Magento/Customer/Api/Data/AddressInterface.stub
818
- ./stubs/Magento/Customer/Api/Data/CustomerInterface.stub
19+
- ./stubs/Magento/Customer/Model/EmailNotificationInterface.stub
20+
- ./stubs/Magento/Eav/Api/Data/AttributeOptionInterface.stub
921
- ./stubs/Magento/Eav/Api/Data/AttributeSetInterface.stub
10-
- ./stubs/Magento/Eav/Model/Entity/Attribute/Option.stub
22+
- ./stubs/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.stub
23+
- ./stubs/Magento/Eav/Model/Entity/Attribute/Source/SourceInterface.stub
24+
- ./stubs/Magento/Eav/Model/Entity/Collection/AbstractCollection.stub
1125
- ./stubs/Magento/Eav/Setup/EavSetup.stub
1226
- ./stubs/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProviderInterface.stub
27+
- ./stubs/Magento/Framework/Api/CustomAttributesDataInterface.stub
28+
- ./stubs/Magento/Framework/Api/ExtensibleDataInterface.stub
29+
- ./stubs/Magento/Framework/Data/Collection.stub
30+
- ./stubs/Magento/Framework/Data/Collection/AbstractDb.stub
31+
- ./stubs/Magento/Framework/Data/Collection/EntityFactoryInterface.stub
32+
- ./stubs/Magento/Framework/Data/OptionSourceInterface.stub
33+
- ./stubs/Magento/Framework/DataObject.stub
1334
- ./stubs/Magento/Framework/DB/Adapter/AdapterInterface.stub
35+
- ./stubs/Magento/Framework/Escaper.stub
36+
- ./stubs/Magento/Framework/Exception/LocalizedException.stub
1437
- ./stubs/Magento/Framework/GraphQl/Config/Element/Field.stub
15-
- ./stubs/Magento/Framework/GraphQl/Query/ResolverInterface.stub
1638
- ./stubs/Magento/Framework/GraphQl/Query/Resolver/ContextInterface.stub
39+
- ./stubs/Magento/Framework/GraphQl/Query/ResolverInterface.stub
1740
- ./stubs/Magento/Framework/GraphQl/Schema/Type/ResolveInfo.stub
1841
- ./stubs/Magento/Framework/Indexer/IndexerActionInterface.stub
19-
- ./stubs/Magento/Framework/Mview/MviewActionInterface.stub
42+
- ./stubs/Magento/Framework/Model/AbstractExtensibleModel.stub
43+
- ./stubs/Magento/Framework/Model/AbstractModel.stub
2044
- ./stubs/Magento/Framework/Model/ResourceModel/Db/AbstractDb.stub
45+
- ./stubs/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.stub
46+
- ./stubs/Magento/Framework/Mview/MviewActionInterface.stub
2147
- ./stubs/Magento/Quote/Api/Data/CartItemInterface.stub
48+
- ./stubs/Magento/Quote/Model/Quote/Address.stub
49+
- ./stubs/Magento/Quote/Model/Quote/Item.stub
2250
- ./stubs/Magento/Quote/Model/Quote/Item/AbstractItem.stub
2351
- ./stubs/Magento/Sales/Api/Data/OrderInterface.stub
2452
- ./stubs/Magento/Sales/Api/Data/OrderItemInterface.stub
53+
- ./stubs/Magento/UrlRewrite/Model/ResourceModel/UrlRewriteCollection.stub
54+
- ./stubs/Magento/UrlRewrite/Model/UrlRewrite.stub
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Magento\Bundle\Model\ResourceModel\Selection;
4+
5+
use Magento\Catalog\Model\Product;
6+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
7+
8+
class Collection extends ProductCollection
9+
{
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Api\Data;
4+
5+
use Magento\Framework\Api\ExtensibleDataInterface;
6+
7+
interface ProductAttributeMediaGalleryEntryInterface extends ExtensibleDataInterface
8+
{
9+
/**
10+
* @return int|string|null
11+
*/
12+
public function getPosition();
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Api\Data;
4+
5+
interface ProductCustomOptionValuesInterface
6+
{
7+
/**
8+
* @return int|string|null
9+
*/
10+
public function getOptionTypeId();
11+
}

stubs/Magento/Catalog/Api/Data/ProductInterface.stub

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ interface ProductInterface
88
* @return int|string|null
99
*/
1010
public function getAttributeSetId();
11+
12+
/**
13+
* @return string|null
14+
*/
15+
public function getSku();
1116
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model;
4+
5+
use Magento\Framework\Model\AbstractExtensibleModel;
6+
7+
abstract class AbstractModel extends AbstractExtensibleModel
8+
{
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model;
4+
5+
class Product extends AbstractModel
6+
{
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model\Product;
4+
5+
use Magento\Catalog\Model\Product\Option\Value;
6+
7+
class Option
8+
{
9+
/**
10+
* @return array<Value>|null
11+
*/
12+
public function getValues();
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model\Product\Option;
4+
5+
use Magento\Catalog\Model\Product\Option;
6+
7+
class Repository
8+
{
9+
/**
10+
* @param string $sku
11+
* @return array<Option>
12+
*/
13+
public function getList($sku);
14+
15+
/**
16+
* @param string $sku
17+
* @param int $optionId
18+
* @return Option
19+
*/
20+
public function get($sku, $optionId);
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model\Product\Option;
4+
5+
class Value
6+
{
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model\ResourceModel\Collection;
4+
5+
use Magento\Eav\Model\Entity\Collection\AbstractCollection as AbstractEavCollection;
6+
use Magento\Framework\DataObject;
7+
8+
/**
9+
* @template T of DataObject
10+
* @extends AbstractEavCollection<T>
11+
*/
12+
class AbstractCollection extends AbstractEavCollection
13+
{
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model\ResourceModel\Product;
4+
5+
use Magento\Catalog\Model\Product;
6+
use Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection;
7+
8+
/**
9+
* @extends AbstractCollection<Product>
10+
*/
11+
class Collection extends AbstractCollection
12+
{
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Magento\Catalog\Model\ResourceModel\Product;
4+
5+
class CollectionFactory
6+
{
7+
/**
8+
* @param array<mixed> $data
9+
* @return Collection
10+
*/
11+
public function create(array $data = []);
12+
}

stubs/Magento/Customer/Api/Data/CustomerInterface.stub

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Magento\Customer\Api\Data;
44

5-
interface CustomerInterface
5+
use Magento\Framework\Api\CustomAttributesDataInterface;
6+
7+
interface CustomerInterface extends CustomAttributesDataInterface
68
{
79
/**
810
* @return int|string|null
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Magento\Customer\Model;
4+
5+
use Magento\Customer\Api\Data\CustomerInterface;
6+
use Magento\Framework\Exception\LocalizedException;
7+
8+
interface EmailNotificationInterface
9+
{
10+
/**
11+
* Send email with new account related information
12+
*
13+
* @param CustomerInterface $customer
14+
* @param string $type
15+
* @param string $backUrl
16+
* @param int|string|null $storeId
17+
* @param string $sendemailStoreId
18+
* @return void
19+
* @throws LocalizedException
20+
*/
21+
public function newAccount(
22+
CustomerInterface $customer,
23+
$type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
24+
$backUrl = '',
25+
$storeId = null,
26+
$sendemailStoreId = null
27+
): void;
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Magento\Eav\Api\Data;
4+
5+
interface AttributeOptionInterface
6+
{
7+
/**
8+
* Get option label
9+
*
10+
* @return string|null
11+
*/
12+
public function getLabel();
13+
}

stubs/Magento/Eav/Model/Entity/Attribute/Option.stub

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Magento\Eav\Model\Entity\Attribute\Source;
4+
5+
abstract class AbstractSource implements
6+
\Magento\Eav\Model\Entity\Attribute\Source\SourceInterface,
7+
\Magento\Framework\Option\ArrayInterface
8+
{
9+
/**
10+
* @var array<int, array{value: int|string, label: string, __disableTmpl?: bool}>|null
11+
*/
12+
protected $_options = null;
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Magento\Eav\Model\Entity\Attribute\Source;
4+
5+
interface SourceInterface
6+
{
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Magento\Eav\Model\Entity\Collection;
4+
5+
use Magento\Framework\DataObject;
6+
use Magento\Framework\Data\Collection\AbstractDb;
7+
8+
/**
9+
* @template T of DataObject
10+
* @extends AbstractDb<T>
11+
*/
12+
abstract class AbstractCollection extends AbstractDb
13+
{
14+
}

stubs/Magento/Eav/Setup/EavSetup.stub

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22

33
namespace Magento\Eav\Setup;
44

5+
use Magento\Framework\Exception\LocalizedException;
6+
57
class EavSetup
68
{
79
/**
810
* @param string|int $entityType
911
* @return string|int
1012
*/
11-
public function getDefaultAttributeSetId($entityType) {}
13+
public function getDefaultAttributeSetId($entityType);
1214

1315
/**
1416
* @param int|string $entityTypeId
1517
* @param int|string $id
1618
* @return int|string|false
1719
*/
18-
public function getAttributeId($entityTypeId, $id) {}
20+
public function getAttributeId($entityTypeId, $id);
21+
22+
/**
23+
* @param int|string $entityTypeId
24+
* @param int|string $setId
25+
* @param int|string $groupId
26+
* @return int|string
27+
* @throws LocalizedException
28+
*/
29+
public function getAttributeGroupId($entityTypeId, $setId, $groupId);
1930

2031
/**
2132
* @param int|string $entityTypeId
@@ -24,5 +35,5 @@ class EavSetup
2435
* @param mixed $value
2536
* @return $this
2637
*/
27-
public function updateAttributeSet($entityTypeId, $id, $field, $value = null) {}
38+
public function updateAttributeSet($entityTypeId, $id, $field, $value = null);
2839
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Magento\Framework\Api;
4+
5+
interface CustomAttributesDataInterface extends ExtensibleDataInterface
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Magento\Framework\Api;
4+
5+
interface ExtensibleDataInterface
6+
{
7+
}

0 commit comments

Comments
 (0)