Questions tagged [phpdoc]
phpDocumentor (phpdoc) is an automatic code-documentation tool for PHP, based on Javadoc.
896
questions
0
votes
1
answer
34
views
How to auto generate all phpdoc comments for a specific custom class?
This github file contains this auto-generated phpdoc comment
/**
* ...
* <autodoc generated by `composer phpdoc`>
*
* @property int $year
* @property int ...
0
votes
1
answer
52
views
Describe an array containing an object (stdClass) with @phpstan-return in PHP DocBlock? - PHPStan
I have an example function in PHP (8.2) that returns an array. Inside this array there is also an object, more precisely stdClass.
I use PHPStan as a static analyzer tool. How can I specify this (...
-3
votes
0
answers
16
views
Does PHPDoc affect the behavior/logic of the code at runtime?
From my understanding, basically, PHPDoc is just comments, but it aim to describe what the code (function, variable, class...) do, how many params, type hinting... so IDE, and code analysis tools can ...
0
votes
1
answer
57
views
PhpDocs: Link to another method in "@param" tag's description?
Is it possible to link to another method/class/property/etc of my project, inline inside the @param tag?
Like this:
/**
* My method's description.
*
* @param string $myArg Pass here result of {@...
0
votes
0
answers
24
views
How to add hint for return folder path in PhpStorm?
<?php
namespace Some\NamespacePath;
class Path {
function library(): string {
$namespaceParts = explode('\\', __NAMESPACE__);
return dirname(__DIR__, count($namespaceParts) + ...
0
votes
1
answer
33
views
Is there any way to automate refactoring old style comments to phpDoc format?
I'm refactoring a huge amount of code which has all function documented in simple comments like this:
//This is foo funtion
function foo($foo)
{
}
And my goal is to make it looks like this:
/**
...
0
votes
0
answers
32
views
PhpDoc show indirect extended method
We have some magic behaviour that adds additional features to class.
Right now we have lots of similar code:
/**
* @see \App\Behaviour::someMethod
* @method mixed someMethod(string ...$params)
*
* ...
0
votes
0
answers
22
views
Root level file not included in phpdocumentor
I'm trying phpdocumentor for the first time and have it mostly working for a custom WP Plugin we're working on. The only problem is I can't get it to include the main plugin file. All the elements in ...
0
votes
1
answer
100
views
PhpStorm PHPDoc type inference: is there a way to manipulate an array and let PhpStorm know its type is same as the original array?
An example is better than any explaining: Let's say I have the following code
function arrayToIdMap(array $models) : array
{
$result = [];
foreach ($models as $model) {
/** @var ...
0
votes
0
answers
18
views
The @propery tag in the class description breaks doc file
I am trying to document php project using doxygen and have a problem.
In the project that I am working on, developers often use the @property tag. PHPDoc supports it and calls it the "Magic" ...
0
votes
0
answers
23
views
PHP: Understanding @templates annotation with the use of @throws tags
I'am using PhpStorm and have started using @template annotations.
However, I have trouble understanding exactly how they work in relation to @throws tags.
Here are some examples (of fantasy) to ...
0
votes
0
answers
28
views
Display @var of Docblock in phpDocumentor
I need to document my php project (a personal project to manage analog photos that got out of hand), and I found dockbloks
So I have created this:
/**
* Called from: some file.php
*
* Purpose: ...
2
votes
1
answer
54
views
How to document PHP Array keys and INI files
When using phpdoc doc blocks, is it possible to describe the keys for an array?
/**
* @var array
*/
private $smtpSettings
= array(
'SMTPDebug' => (bool)true,
'SMTPSecure' =>...
1
vote
0
answers
272
views
PhpStorm Generic Classes not working at all
This is all happening for me in PhpStorm 2022.2.1
I've been trying to set up a class in PHP that supports Generics, but to no avail. No matter what I tried, PhpStorm always type hints as mixed. Here ...
1
vote
1
answer
36
views
CakePHP: How to update the Models PHPDocs?
I have a huge project with 100+ tables in my database. Over the years, we add some new columns in some tables, but we forgot to reflect this on Models phpDocs. Those phpdocs were initially generate by ...
0
votes
2
answers
124
views
PhpStorm 2022.2.2 Laravel Model Relationships and Attributes recognised as magic methods
How can I declare my model relationships and custom attributes properly so that they will be available from auto-completion and have the warning "property accessed via magic method" ...
0
votes
0
answers
31
views
Type hint function signature of callable with parameters in PHP
Sorry if this is a duplicate, I searched everywhere and couldn't find any answers.
In TypeScript, we can define function types with the following syntax:
interface Foo {
callback: (arg1: string, ...
0
votes
1
answer
2k
views
How to autogenerate phpDOC for classes/function on VSCode
Any idea how to generate phpdoc on VSCode? I have installed intellisense, intelephense extensions but when I type /** it just adds */ so it becomes something like
/** */ and that's all. No ...
0
votes
0
answers
527
views
How to understand this phpStan error (has parameter $astTreeData with no value type specified in iterable type array.)
Say I have a formatter function like this:
function prepareValue(mixed $value): string
{
...
return "{$value}";
}
/**
* @param array<int, array> $astTreeData
* @return ...
0
votes
0
answers
284
views
UndefinedDocblockClass psalm error when using a trait to mark magic properties as deprecated
I'm trying to use PhpDoc to hint all the deprecated magic properties set on a Laravel Model using the mixin described in this answer.
I am using JetBrains PhpStorm 2022.1.1, PHP 8.1.6 and Psalm 4.23.0
...
0
votes
0
answers
16
views
Phpdoc create custom sidebar items
Is there some way to create items on the sidebar of phpdoc page with custom text?
At this point my documentation it's created correctly however it would be fun can add more informations here.
0
votes
0
answers
26
views
Php, code competion for inline-factory / dynamic method name?
given this snippet:
class Test
{
public function run2()
{
}
}
class Factory
{
public function createTest()
{
return new Test();
}
}
$factory = new Factory();
$m = '...
0
votes
0
answers
53
views
Psalm not show attributes methods errors in another file
If I call the method \Test\MyClass::test('string'); in file 1. psalm work correct and show error "psalm: InvalidScalarArgument: Argument 1 of..."
Why in file 2 psalm dont show attributes ...
0
votes
0
answers
75
views
How to use custom annotations to document code in php
In my php code I have a lot of places, where I need to customize the default behaviour of the programming logic for different customers. For documentation purposes I want to annonate every custom ...
0
votes
2
answers
153
views
Method @returns a child class of an property
I have a abstract class Foo and a abstract builder FooBuilder
abstract class Foo {
}
abstract class FooBuilder {
protected Foo $model;
/**
* Return the class instance
*
* @return Model //...
0
votes
0
answers
357
views
VSCode User Snippet for PHPDoc comments
I am trying to create a user snippet for adding a PHPdoc comment. It works fairly well but I am having a sort of annoying issue where once I hit enter to go to a new line in the comment I have to add ...
0
votes
0
answers
41
views
PHPWORD generates "mirrored" table instead of normal
I use PHPWORD library to generate .docx document with a simple table.
This is the code:
require "vendor/autoload.php";
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->...
0
votes
0
answers
45
views
Is there a way to remove the default package called application showing in PHPDocumentator?
PHPDoc shows a default application package, and cannot figure out how to remove it.
1
vote
0
answers
45
views
How to document thrown exceptions with a PHPdoc tag `@method`? [duplicate]
Is there any way how I can also document the thrown exceptions if the method is documented via the PHPdoc tag @method? According to the official documentation on @method this seems impossible. But ...
0
votes
1
answer
651
views
PHPDoc & Psalm - Annotate an "array of classes"
In my code I created an EventFactory like this:
private array $events = [
'post_created' => PostCreatedEvent::class,
'exercise_executed' => ExerciseExecutedEvent::class,
];
public ...
0
votes
1
answer
52
views
PHP OOP DocBlock @var for $this->var
A class "DerivedClass" extends "BaseClass". It instantiates an object of type ProcessDerived, passing $this to the constructor:
$object = new ProcessDerived($this); // $this ...
1
vote
1
answer
487
views
PhpStorm: what is the best way to handle "return value is expected to be ..." warning?
My PHP code is structured to be something like follows (this structure is unchangeable):
class BaseFooClass {
}
class ChildFooClass1 extends BaseFooClass {
}
class ChildFooClass2 extends ...
2
votes
2
answers
2k
views
How to replace phpdocs with new attributes in php 8
I am using laravel. I need to know how phpdoc can be written in php 8 with attibutes.
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @...
5
votes
1
answer
480
views
How can I serve generated phpDocumentor docs from Laravel?
So I'm using phpDocumentor 3 to generate documentation for my Laravel 7 project,
and was wondering if I could serve this documentation (static files) from Laravel in order to make it available only to ...
2
votes
0
answers
110
views
How to deal with PHPDoc blocks and print width PHPCS/PHPMD rules?
I'm developing a Laravel application, and I use PHPCS, PHPMD and Prettier.
I have a Facade to deal with the invitation system of the app, and the PHPDoc (at the time of writing) looks like this:
/**
*...
1
vote
0
answers
79
views
PhpDoc annotations: how to 'point' a variable just in one place
class SomeClass {
/** @var AdaptedClass */
private $adaptor;
public function __construct() {
$adaptorClassName = 'AdaptedClass';
if (class_exists($adaptorClassName)) {
...
0
votes
1
answer
794
views
Generate documentation with phpDocumentor (phpdoc) for Laravel package model
I'm trying to use phpDocumentor to generate my Laravel package documentation, but I'm finding not-as-easy-as-I-tought to generate a usage-oriented documentation.
What i mean is: how should I write ...
3
votes
1
answer
2k
views
What does the annotation @template mean in PHP doc blocks?
I could see this PHPDoc block in the FakerPHP/Faker package, and I'm not aware what does @template mean? you can find it in the package's main branch on this line
/**
* @template T of Extension\...
0
votes
1
answer
173
views
How can I add custom/dynamic/magic PHP function definitions to Sublime Text?
I know Sublime Text isn't an IDE, but that's what I like about it. Still, it's nice to have certain IDE-esque functionality from time to time.
Mostly for use with Laravel, I'd like the ability for ...
0
votes
1
answer
36
views
Explicit typing on property of instance
To help my editor better understand my code, I sometimes need to add a comment like this:
/* @var $container Container */
This work good, but sometimes I would need something like this:
/* @var $this-...
-1
votes
1
answer
39
views
How to instal phpDocumntor on Symfony4?
I'm trying to install phpDocumentor on my project, but I've got this problem.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- phpdocumentor/phpdocumentor[...
0
votes
1
answer
399
views
Commenting functions with phpdoc adds "use" at the top of classes in laravel. Does it make the application slower?
Writing comments for Laravel functions with phpdoc requires to add classes. For example
/**
* Add item to cart and redirect back
*
* @return Response
*/
Automatically adds &...
2
votes
0
answers
125
views
PHPDoc - Dynamic Function Names and Return Types for IDE
I'm working on (somebody else's) application. I'm not sure what framework it uses if any, but it allows calls like this
Users:findByUsername('josh');
Which will return one instantiated User object/...
2
votes
1
answer
170
views
Is there any way of using an object type in @property-read and "declare" its attributes?
I want to add a type of object in @property-read and also be able to access its attributes with PhpStorm suggestions.
Here's what I would like to do:
/**
* @property-read object{type: string, schema: ...
2
votes
1
answer
1k
views
How to navigate Laravel model scopes in PhpStorm
I have a model CheckingAccount with scopes:
//scopes
public function scopeEmailLike(Builder $builder, $email)
{
return $this->where($this->table . '.email', 'like', '%' . $email . '%');
}
...
0
votes
1
answer
83
views
PHPDoc for object made from array
I have config.php file with following rules:
return [
'debug' => true,
'db_debug' => true,
'lang' => 'Eng',
...
And so on. When my app initializes, this file will be used ...
7
votes
1
answer
2k
views
How to typehint generators in php?
Assume you have a class like:
class MyClass
{
public function __construct(public int $id, public string $foo)
{
}
}
and a generator creating multiple instances of that class like this:
$...
1
vote
0
answers
362
views
How to indicate very specific values for PHPDoc's @return?
I have a method:
public function getHttpMethod(): string
{
return $this->httpMethod;
}
how can I indicate that $this->httpMethod value is always string "get" or string "post&...
1
vote
0
answers
211
views
phpDocumentor generate class hierarchy diagram
I am discovering phpDocumentor to generate documentation from my php code. I achieved to generate a html file with the api documentation. But I found a tab called "class hierarchy diagram" ...
-1
votes
1
answer
115
views
Regex for matching multi-line PHPDoc comments
/**
* Get Data
*
* @param null|ProductInterface $product
*
* @return string
* @throws LocalizedException
* @throws NoSuchEntityException
*/
I would like to find PHPDoc multi-lines using the ...