Rules to create file level #package - php

My code looks like this:
/**
* #package Test
*/
require_once('foo.php');
/**
* Main class
*/
class Test{
}
/**
* Generic exception
*/
class Test_Excepcion extends Exception{
}
I want the first docblock to be a file level block, but ApiGen seems to link it to the require statement and my classes show up in the "None" namespace. It gets fixed if I do e.g. this:
/**
* #package Test
*/
//
require_once('foo.php');
Is this the intended behaviour? Do I need to add a bogus comment after the file level block? What are the precise rules?

The #package tag is not necessarily a file-level block. You can specify the #package tag for each class in your file. Like this:
/**
* Main class
* #package Test
*/
class Test{}

Related

PHPStan configuration for FuelPHP

I am having a lot of trouble getting PHPStan to see the FuelPHP core classes. It would appear this sort of thing causes it grief:
namespace Fuel\Core;
/**
* Template Controller class
*
* A base controller for easily creating templated output.
*
* #package Fuel
* #category Core
* #author Fuel Development Team
*/
abstract class Controller_Template extends \Controller
{
/**
* #var string page template
*/
public $template = 'template';
Where Controller is also in the Fuel\Core namespace:
namespace Fuel\Core;
abstract class Controller
{
/**
* #var Request The current Request object
*/
public $request;
It looks like PHPStan can's find Controller because it is looking in the root namespace. FuelPHP gets around this (magic? autoloading? aliasing?). Is there a way to get PHPStan to jump on the same bandwagon, or do I need to stub out all the core classes I'm using?
Did you try to follow this guide? PHPStan: Discovering symbols
I helped set up FuelCMS analysis in the past. What worked for that user was this phpstan.neon:
parameters:
scanDirectories:
- core/classes
bootstrapFiles:
- core/classes/autoloader.php
There's an example repository that works: https://github.com/ondrejmirtes/phpstan_problem/tree/fix
For some reason the phpstan.neon is buried in app/classes/controller while it should definitely be in the root directory. But otherwise it works.

doxygen doesnt seem to work well with class_exists-Method

I want to use doxygen for document my PHP-Project (it's a Wordpress Plugin).
To be save, that I do not overwrite a existing class from any other Wordpress Plugin, I use the "class_exist"-Method.
But now, doxygen is only generate a documentation for my class, if i do any php call before my class definition.
An example:
/**
* #author schmitt
*
* #file my_util_class.php
*
* #class my_util_class
*
* #brief small message
*
* big message
*/
if ( ! class_exists( 'my_util_class' ) ) :
//echo "hallo";
class my_util_class
{
/**
* #brief smalltest
* bigtestmessage
*/
public function test() {
return "hallo";
}
//definition of other methods.
}
endif;
if i comment out the line echo "hallo" doxygen will generate a fully documentation of my class with all Methods.
But if the line is commented, only the header (defined with #file etc.) will documented well. None of the methods is going to be documented.
I have set the "Extract All" Parameter in the doxygen-Config to YES.
But this doesn't help.
Hope someone can help me. Thanks.

Suppress Class DocBlock errors in PHPDoc

Is there any way to suppress particular types of errors in PHPDoc, or direct it not to check for some elements?
I don't need a DocBlock for both the file and the class. My typical layout is as follows:
<?php
/**
* Registration service
*
* Coordinates the registration actions for users. These are ...
*
* #version a.4.2
* #author My Name <me at example.com>
*/
namespace MyProject\Service;
use Other\Namespace;
class Registration extends AbstractService
{
// ...
In this case, PHPDoc complains that I have no class summary. I can remedy the problem by copying the DocBlock and pasting it immediately above the class declaration, but I'm hoping for a better solution.
If I'm not mistaken, and I didn't test this, you could do something like this:
<?php
namespace MyProject\Service;
use Other\Namespace;
/**
* Registration service
*
* Coordinates the registration actions for users. These are ...
*
* #version a.4.2
* #author My Name <me at example.com>
*/
class Registration extends AbstractService
{
// ...
At least the docblock should now be recognised as a class doc instead of a file doc, which is more accurate in this particular example.
To try and answer your original question, actually suppressing the error, you could try this answer (it describes using the command line --packageoutput argument).

PHPUnit-Netbeans class not found exception

I integrated PHPUnit into netbeans and now want to generate tests for my code.
<?php
/**
* Action User
*
* user api
*
* #link http://getfrapi.com
* #author Frapi <frapi#getfrapi.com>
* #link rsmobile/user/:id
*/
class Action_User extends Frapi_Action implements Frapi_Action_Interface
{
}
?>
I tried to do that by right clicking and selecting Tools->Create PHPUnit Tests. But it gave this error :
Fatal error: Class 'Frapi_Action' not found in /Users/username/Documents/.../src/
frapi/custom/Action/User.php on line 12
Then I added dummy Frapi_Action class in file User.php and then it generated skeleton class.
<?php
/**
* Action User
*
* user api
*
* #link http://getfrapi.com
* #author Frapi <frapi#getfrapi.com>
* #link rsmobile/user/:id
*/
class Frapi_Action {}
class Action_User extends Frapi_Action implements Frapi_Action_Interface
{
}
?>
Why it gave that Class not found error? How do I solve it?
I solved it by adding path of the file containing Frapi_Action class.
require_once 'path/of/file';
Your class is not in the source code in the original example. You either need to include/require the external file containing the class (recommended) or have the class in this code.

phpdoc keeps telling me my page-level docblock is not present

PHPDocumenter keeps telling me that my page-level docblock is not present in my file, i read several pages of documentation online to make this work but still doesn't work, anyone know whats wrong?
<?php
namespace Activis\Catalog\Model;
/**
* This file represents the factory for the domain object Product for the Activis catalog.
*
* For now, this factory is simple and abstract but will slowly change into a non-static set of factory functions
* The domain model for this object is \Activis\Catalog\Model\Product
*
* #category Domain model factory
* #package Activis.Catalog.Model
* #author Mathieu Dumoulin
* #license LGPL v3
* #link http://activis.ca/
* #todo Change the methods in the factory to not be abstract and require an instance of this class
*/
/**
* Declares the catalog's product's domain model factory
*
* #abstract
* #static
*/
abstract class ProductFactory
{
}
Page-level docblock should be placed on top of file, before namespace declarations

Categories