Skip to content
Snippets Groups Projects
Commit 843c7843 authored by David Prévot's avatar David Prévot
Browse files

New upstream version 1.10.0

parents 63806ba6 679e3ce4
No related branches found
No related tags found
No related merge requests found
Pipeline #763440 failed
Showing
with 409 additions and 62 deletions
name: "Documentation"
on: # yamllint disable-line rule:truthy
push:
branches:
- "1.x"
pull_request: null
jobs:
documentation:
name: "Documentation"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
- name: "Build"
uses: "phpDocumentor/phpDocumentor@master"
- name: "Deploy"
if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/1.x' }}"
uses: "actions/upload-artifact@v4"
with:
name: "documentation"
path: "build/docs"
retention-days: 1
deploy:
name: "Deploy"
if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/1.x' }}"
runs-on: "ubuntu-latest"
needs: "documentation"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
repository: "phpDocumentor/docs"
token: "${{ secrets.BOT_TOKEN }}"
path: "docs"
- name: "Download"
uses: "actions/download-artifact@v4"
with:
name: "documentation"
path: "build/docs"
- name: "Copy files"
run: "rsync -r --delete build/docs/* docs/docs/components/type-resolver"
- name: "Commit"
uses: "stefanzweifel/git-auto-commit-action@v5"
with:
repository: "docs"
commit_message: "Update type-resolver documentation"
- name: "Push"
uses: "ad-m/github-push-action@master"
with:
directory: "docs"
github_token: "${{ secrets.BOT_TOKEN }}"
repository: "phpDocumentor/docs"
......@@ -21,13 +21,13 @@ jobs:
coding-standards:
name: "Coding Standards"
uses: "phpDocumentor/.github/.github/workflows/coding-standards.yml@v0.5.0"
uses: "phpDocumentor/.github/.github/workflows/coding-standards.yml@v0.8"
with:
composer-root-version: "1.x-dev"
dependency-analysis:
name: "Dependency analysis"
uses: "phpDocumentor/.github/.github/workflows/dependency-analysis.yml@v0.5.0"
uses: "phpDocumentor/.github/.github/workflows/dependency-analysis.yml@v0.8"
with:
composer-root-version: "1.x-dev"
......@@ -39,13 +39,14 @@ jobs:
static-analysis:
name: "Static analysis"
uses: "phpDocumentor/.github/.github/workflows/static-analysis.yml@v0.5.0"
uses: "phpDocumentor/.github/.github/workflows/static-analysis.yml@v0.8"
with:
php-extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, fileinfo, pcntl, posix"
composer-root-version: "1.x-dev"
unit-tests:
name: "Unit test"
uses: "phpDocumentor/.github/.github/workflows/continuous-integration.yml@v0.5.0"
uses: "phpDocumentor/.github/.github/workflows/continuous-integration.yml@v0.8"
with:
composer-root-version: "1.x-dev"
upcoming-releases: true
{% extends 'layout.html.twig' %}
{% set topMenu = {
"menu": [
{ "name": "About", "url": "https://phpdoc.org/"},
{ "name": "Components", "url": "https://phpdoc.org/components.html"},
{ "name": "Documentation", "url": "https://docs.phpdoc.org/"},
],
"social": [
{ "iconClass": "fab fa-mastodon", "url": "https://phpc.social/@phpdoc"},
{ "iconClass": "fab fa-github", "url": "https://github.com/phpdocumentor/typeresolver"},
{ "iconClass": "fas fa-envelope-open-text", "url": "https://github.com/orgs/phpDocumentor/discussions"}
]
}
%}
......@@ -41,3 +41,7 @@ rector: ## Refactor code using rector
.PHONY: pre-commit-test
pre-commit-test: fix-code-style test code-style static-code-analysis
.PHONY: docs
docs: ## Generate documentation with phpDocumentor
docker run -it --rm -v${CURDIR}:/opt/project -w /opt/project phpdoc/phpdoc:3
......@@ -2,7 +2,7 @@
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor", "PHPStan\\PhpDocParser\\ParserConfig",
"T_NAME_QUALIFIED", "T_NAME_FULLY_QUALIFIED"
],
"php-core-extensions" : [
......
......@@ -12,7 +12,7 @@
"require": {
"php": "^7.3 || ^8.0",
"phpdocumentor/reflection-common": "^2.0",
"phpstan/phpdoc-parser": "^1.13",
"phpstan/phpdoc-parser": "^1.18|^2.0",
"doctrine/deprecations": "^1.0"
},
"require-dev": {
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6db1e320c0ec65669131eb815d876ec5",
"content-hash": "142e0ed9e505415b092f3963da4939cc",
"packages": [
{
"name": "doctrine/deprecations",
......@@ -108,16 +108,16 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.25.0",
"version": "1.27.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240"
"reference": "86e4d5a4b036f8f0be1464522f4c6b584c452757"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240",
"reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/86e4d5a4b036f8f0be1464522f4c6b584c452757",
"reference": "86e4d5a4b036f8f0be1464522f4c6b584c452757",
"shasum": ""
},
"require": {
......@@ -149,9 +149,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0"
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.27.0"
},
"time": "2024-01-04T17:06:16+00:00"
"time": "2024-03-21T13:14:53+00:00"
}
],
"packages-dev": [
......
===============
Getting started
===============
On this page you will find a brief introduction on how to use the TypeResolver in your project.
Installation
============
The TypeResolver is available on Packagist and can be installed using Composer:
.. code:: bash
composer require phpdocumentor/type-resolver
General usage
===========
After you installed the TypeResolver you can use it in your project. This can be done by creating a new instance
of the :php:class:`\phpDocumentor\Reflection\TypeResolver` class and calling
:php:method:`\phpDocumentor\Reflection\TypeResolver::resolve()` with the type you want to resolve.
.. code:: php
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
$type = $typeResolver->resolve('string');
echo get_class($type); // phpDocumentor\Reflection\Types\String_
The real power of this resolver is in its capability to expand partial class names into fully qualified class names;
but in order to do that we need an additional :php:class:`\phpDocumentor\Reflection\Types\Context` class that
will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
Read more about the Context class in the next section.
=============
Type resolver
=============
This project part of the phpDocumentor project. It is capable of creating an object structure of the type
specifications found in the PHPDoc blocks of a project. This can be useful for static analysis of a project
or other behavior that requires knowledge of the types used in a project like automatically build forms.
This project aims to cover all types that are available in PHPDoc and PHP itself. And is open for extension by
third party developers.
.. toctree::
:maxdepth: 2
:hidden:
index
getting-started
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="data/xsd/phpdoc.xsd"
>
<title>Type Resolver</title>
<paths>
<output>build/docs</output>
</paths>
<version number="0.2.0">
<folder>latest</folder>
<api>
<source dsn="./">
<path>src/</path>
</source>
<output>api</output>
<ignore hidden="true" symlinks="true">
<path>tests/**/*</path>
<path>build/**/*</path>
<path>var/**/*</path>
<path>vendor/**/*</path>
</ignore>
<extensions>
<extension>php</extension>
</extensions>
<ignore-tags>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
<default-package-name>phpDocumentor</default-package-name>
</api>
<guide>
<source dsn=".">
<path>docs</path>
</source>
<output>guides</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<template name="default" />
</phpdocumentor>
......@@ -7,3 +7,20 @@ parameters:
- tests/benchmark/Assets/*
paths:
- src
ignoreErrors:
-
message: "#^Parameter \\#1 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser\\|null, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/TypeResolver.php
-
message: "#^Parameter \\#1 \\$parseDoctrineAnnotations of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/TypeResolver.php
-
message: "#^Parameter \\#1 \\$unescapeStrings of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/TypeResolver.php
-
message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
count: 1
path: src/TypeResolver.php
......@@ -38,5 +38,27 @@
<file name="src/TypeResolver.php"/>
</errorLevel>
</RedundantConditionGivenDocblockType>
<InvalidArgument>
<errorLevel type="suppress">
<referencedFunction name="PHPStan\PhpDocParser\Lexer\Lexer::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\ConstExprParser::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
</errorLevel>
</InvalidArgument>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<referencedClass name="PHPStan\PhpDocParser\ParserConfig"/>
</errorLevel>
</UndefinedDocblockClass>
<MixedArgument>
<errorLevel type="suppress">
<referencedFunction name="PHPStan\PhpDocParser\Lexer\Lexer::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\ConstExprParser::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
</errorLevel>
</MixedArgument>
</issueHandlers>
</psalm>
......@@ -13,53 +13,6 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Mixed_;
use function sprintf;
final class ArrayShapeItem
class ArrayShapeItem extends ShapeItem
{
/** @var string|null */
private $key;
/** @var Type */
private $value;
/** @var bool */
private $optional;
public function __construct(?string $key, ?Type $value, bool $optional)
{
$this->key = $key;
$this->value = $value ?? new Mixed_();
$this->optional = $optional;
}
public function getKey(): ?string
{
return $this->key;
}
public function getValue(): Type
{
return $this->value;
}
public function isOptional(): bool
{
return $this->optional;
}
public function __toString(): string
{
if ($this->key !== null) {
return sprintf(
'%s%s: %s',
$this->key,
$this->optional ? '?' : '',
(string) $this->value
);
}
return (string) $this->value;
}
}
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
use function implode;
/** @psalm-immutable */
final class ListShape extends ArrayShape
{
public function __toString(): string
{
return 'list{' . implode(', ', $this->getItems()) . '}';
}
}
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
final class ListShapeItem extends ArrayShapeItem
{
}
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Mixed_;
/**
* Value Object representing the type 'non-empty-array'.
*
* @psalm-immutable
*/
final class NonEmptyArray extends Array_ implements PseudoType
{
public function underlyingType(): Type
{
return new Array_($this->valueType, $this->keyType);
}
/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
if ($this->keyType) {
return 'non-empty-array<' . $this->keyType . ',' . $this->valueType . '>';
}
if ($this->valueType instanceof Mixed_) {
return 'non-empty-array';
}
return 'non-empty-array<' . $this->valueType . '>';
}
}
......@@ -28,7 +28,7 @@ final class NonEmptyList extends Array_ implements PseudoType
{
public function underlyingType(): Type
{
return new Array_();
return new Array_($this->valueType, $this->keyType);
}
public function __construct(?Type $valueType = null)
......
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Object_;
use function implode;
/** @psalm-immutable */
final class ObjectShape implements PseudoType
{
/** @var ObjectShapeItem[] */
private $items;
public function __construct(ObjectShapeItem ...$items)
{
$this->items = $items;
}
/**
* @return ObjectShapeItem[]
*/
public function getItems(): array
{
return $this->items;
}
public function underlyingType(): Type
{
return new Object_();
}
public function __toString(): string
{
return 'object{' . implode(', ', $this->items) . '}';
}
}
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
final class ObjectShapeItem extends ShapeItem
{
}
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Mixed_;
use function sprintf;
abstract class ShapeItem
{
/** @var string|null */
private $key;
/** @var Type */
private $value;
/** @var bool */
private $optional;
public function __construct(?string $key, ?Type $value, bool $optional)
{
$this->key = $key;
$this->value = $value ?? new Mixed_();
$this->optional = $optional;
}
public function getKey(): ?string
{
return $this->key;
}
public function getValue(): Type
{
return $this->value;
}
public function isOptional(): bool
{
return $this->optional;
}
public function __toString(): string
{
if ($this->key !== null) {
return sprintf(
'%s%s: %s',
$this->key,
$this->optional ? '?' : '',
(string) $this->value
);
}
return (string) $this->value;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment