Setup Yii 2 Web Framework Coding Standard in NetBeans - php

I read this and this. But how to setup this in NetBeans IDE in Windows machine?

Yii2 requires PHP 5.4 minimum, so if your IDE supports PHP 5.4 or later then it will show standards for Yii2 too.
You can also check this yii pligin for netbeans http://plugins.netbeans.org/plugin/47246/php-yii-framework-netbeans-phpcc

in root of your project make file with name of autocompletion.php and add this to file.
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
* Note: To avoid "Multiple Implementations" PHPStorm warning and make autocomplete faster
* exclude or "Mark as Plain Text" vendor/yiisoft/yii2/Yii.php file
*/
class Yii extends \yii\BaseYii
{
/**
* #var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* #property trntv\filekit\Storage $fileStorage
* #property common\components\keyStorage\KeyStorage $keyStorage
* #property yii\web\UrlManager $urlManagerFrontend UrlManager for frontend application.
* #property yii\web\UrlManager $urlManagerBackend UrlManager for backend application.
* #property yii\web\UrlManager $urlManagerStorage UrlManager for storage application.
* #property trntv\glide\components\Glide $glide
* #property trntv\bus\CommandBus $commandBus
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
*
* #property User $user User component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*/
class ConsoleApplication extends yii\console\Application
{
}
/**
* User component
* Include only Web application related components here
*
* #property \common\models\User $identity User model.
* #method \common\models\User getIdentity() returns User model.
*/
class User extends \yii\web\User
{
}

Related

How to declare columns on models?

I want my Code Completion (PhpStorm) to work with Eloquent models but if I declare fields corresponding to DB columns they no longer work:
class Limit extends Model
{
public $id;
public $type;
public $limit;
}
Is there some workaround?
(This is a slightly modified version of my own reply from this thread: Eloquent ORM Code Hinting in PhpStorm)
The laravel-ide-helper package can be used to help with this issue, by generating PHPDocs for your models.
You can generate a separate file for all PHPDocs with this command:
php artisan ide-helper:models
The generated metadata will look something like this for each class:
namespace App {
/**
* App\Post
*
* #property integer $id
* #property integer $author_id
* #property string $title
* #property string $text
* #property \Carbon\Carbon $created_at
* #property \Carbon\Carbon $updated_at
* #property-read \User $author
* #property-read \Illuminate\Database\Eloquent\Collection|\Comment[] $comments
*/
class Post {}
}
This caused issues for me in PHPStorm however, where the software was complaining about multiple class definitions. Luckily an option is readily available for writing directly to the model files:
php artisan ide-helper:models -W
There are a few more options and settings available if you need to tweak the behavior, but this is the gist of it.

phpdoc not documenting anything but the starting docblock

I'm trying to document a sample file:
/**
* ElasticSearch Library
*
* Intended to do some cool stuff
*
*
* #author cmvr
* #subpackage elasticSearch
* #copyright free to use
* #license http://www.gnu.org/copyleft/gpl.html Freely available under GPL
*/
namespace Libs;
/**
* This is the main class of elastic search
*/
class elasticSearch {
protected $dataConnection;
/**
* elastic search setup data connection
* #return boolean
*/
public function setupDataConnection($dataString) {
return true;
}
}
I'm running in the CLI:
phpdoc -f ../../app/libraries/elasticSearch.php -t ../../newDocs
And it's working fine, but when i'm viewing my html ouput here:
newDocs/files/elasticSearch.html
The class and the method setupDataConnection aren't documented at all.
This is the screens i see:
Can anyone explain what am i doing wrong?

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

Is there a way to tell PHPStorm to hide a method/function/variable/etc

I'm looking for a way to make PHPStorm hide some methods from code completion. I've tried to annotate the DocBlocks with #access private but that does not hide them from view.
Is there any way to hide private API, short of writing/generating a stub file with a limited interface and referencing that in my project?
for example:
Lets say the library has this in it:
<?php
interface IDoABunchOfStuff
{
/**
* My library users use this
*/
public function doFoo();
/**
* My Library needs this but requires that my users don't see it.
*
* #access private
* #visibility none
* #package mylib
* #internal
*/
public function doBar();
}
class Foo extends Something implements IDoABunchOfStuff
{
/**
* does foo
*/
public function doFoo()
{
// ...
}
/**
* does bar. for internal use only
*
* #access private
* #visibility none
* #package mylib
* #internal
*/
public function _doBar()
{
// ...
}
}
And my library user is typing:
<?php
myAwesomeFunction(IDoABunchOfStuff $aFoo)
{
if($->$oFoo->[CTRL+SPACE] // invoking code completion...
Is it possible to (and if it is how do I) make it so that my user never sees _doBar?
Neither of the different annotations i've tried seem to have the desired effect.
P.S. I'm using PHPStorm 4.0.3
additional:
In this case I am implementing ArrayAccess and I don't want offsetGet, offsetSet, offsetExists and offsetUnset cluttering up my code completion window but I've had similar problems elsewhere enough to warrant asking a more generalized question.
Nope -- you cannot do such thing in current version of PhpStorm.
There is a ticket on Issue Tracker that suggests using #access tag for this purpose, but currently it is not scheduled to be implemented for any particular version: http://youtrack.jetbrains.com/issue/WI-5788
Feel free to vote/comment/etc and maybe it will be implemented sooner.

Categories