PhpStorm property annotation for instance of class - autocomplete

I know I can use PhpStorm annotations like this:
/**
* Class Model
* #property string name
*/
class Model {};
$modelInstance = new Model();
$modelInstance->name;
When I type $modelInstance-> PhpStorm will offer me "name" in autocomplete.
Is it possible to create custom property annotations for instances of classes?
/**
* Class Model
* #property string name
*/
class Model {};
/**
* #var Model $modelInstance #property text
*/
$modelInstance = new Model();
$modelInstance->text; //PhpStorm does not know about this property
I would like to have property "text" in PhpStorm autocomplete but ONLY for $modelInstance. Not for every instance of class Model.

This is my solution based on LazyOne's opinion.
/**
*
* Class ZboziDibiRow
* #property int id
* #property string name
* #property string store
* #property string uri
* #property string manufacturer
* #property string description
* #property int price
* #property string ean
* #property string code
* #property int available_in
* #property string zbozi_category_id
* #property string category_recursive_id
*/
class ZboziDibiRow extends DibiRow
{
}
Now when I have something like:
/**
* #var ZboziDibiRow[]
*/
public $products;
I will get autocomplete for:
$zbozi = new Zbozi();
foreach ($zbozi->products as $key => $product) {
$product-> ....

Related

How can I document randomly-assigned properties of a custom type in JSDoc?

/**
* #typedef {string} UUID
* */
/**
* #typedef {Object} ITEM
* #property {UUID} id
* */
/**
* #typedef {Object} THINGY
* #property {??????}
* */
const oneThingy = {
asdf: {id: 'asdf', ...},
sdfg: {id: 'sdfg', ...},
dfgh: {id: 'dfgh', ...}
}
Assuming that a THINGY can have infinite k:v pairs, and that the keys will be random UUIDs, how would I document and type the #property?
Thanks to a kind person named Kyriakos on the JSDoc Slack channel, TIL it's not the #property, I just need the properly-formatted #typedef:
/**
* #typedef {string} UUID
* */
/**
* #typedef {Object} ITEM
* #property {UUID} id
* */
/**
* #typedef {Object.<UUID, ITEM>} THINGY // <-- this one
* */
const oneThingy = {
asdf: {id: 'asdf', ...},
sdfg: {id: 'sdfg', ...},
dfgh: {id: 'dfgh', ...}
}

Swagger annotations with linked property array

I'm new to PHP Swagger and using the Laravel package L5-Swagger to create documentation for my API. Now I'm trying to let one model contain an array of the other model, an Order can have several OrderItems.
Unfortuantly I cannot get the linking to work. See attached screen shot.
What am I doing wrong?
This is my Order model:
/**
* #SWG\Definition(
* required={"order_id","order_items"},
* type="object",
* #SWG\Xml(name="Order")
* )
*/
class Order
{
/**
* #SWG\Property(example="O-789456123")
* #var string
*/
public $order_id;
/**
* #SWG\Property(type="array", items="$ref:OrderItem")
* #var array
*/
public $order_items = [];
}
This is my OrderItem model:
/**
* #SWG\Definition(
* required={"sku","quantity", "price_including_tax"},
* type="object",
* #SWG\Xml(name="OrderItem")
* )
*/
class OrderItem
{
/**
* #SWG\Property(example="SKU-123")
* #var string
*/
public $sku;
/**
* #SWG\Property(example=2)
* #var integer
*/
public $quantity;
/**
* #SWG\Property(example=199.75)
* #var float
*/
public $price_including_tax;
}
I think items="$ref:OrderItem" should be #SWG\Items(ref="#/definitions/OrderItem")
Ps. Checking the intermediate format (the swagger.json) can provide insight into what going wrong.

How to make link of method parameter type in jsDoc

Is there any natural way or special tag to make parameter type as link?
/**
* My js app
* #module app
*/
/**
* Namespace for MYAPP classes and functions.
* #namespace HUMAN_RESOURCE
*/
var HUMAN_RESOURCE = HUMAN_RESOURCE || {};
/**
* #class JustClass
* #constructor
*/
HUMAN_RESOURCE.JustClass = function(){ }
/**
* Constructs Person objects
* #class Person
* #constructor
* #param {String} First name
* #param {String} Last name
*/
HUMAN_RESOURCE.Person = function (first, last) {
/**
* First name of the Person
* #property first_name
* #type String
*/
this.first_name = first;
/**
* #property f_createPerson
* #param {Person} [_person] açıklama
* #return {Person} Person type object
*/
this.f_createPerson = function(_person, _person2){ return new Person() }
};
/**
* Return Person's full name
* #alias getName
* #memberof! HUMAN_RESOURCE.Person#
* #return {String} First name + last name
*/
HUMAN_RESOURCE.Person.prototype.getName = function () {
return this.first_name + ' ' + this.last_name;
};
Fortunately yes, it is just not always obvious what the correct name path is (but you can basically see it at the top of your generated docs)
/**
* #property f_createPerson
* #param {module:app~HUMAN_RESOURCE.Person} [_person] açıklama
* #return {module:app~HUMAN_RESOURCE.Person} Person type object
*/
this.f_createPerson = function(_person, _person2){ return new Person() }

EntityNotFoundException in doctrine 2 proxy class

What are the possible causes of EntityNotFoundException while accessing the proxy class properties in doctrine 2? Anyway, the following is my entities' structure:
/**
* #ORM\Table(name="comments")
*
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="comment_type", type="smallint")
* #ORM\DiscriminatorMap({
* 1 = "VisitorComment",
* 2 = "MemberComment"
* })
*/
class Comment
{
//with common properties of its subclasses
}
subclasses are as follows:
/**
* #ORM\Table(name="member_comments")
*/
class MemberComment extends Comment
{
/**
* owning side
*
* #var Member $author
*
* #ORM\ManyToOne(targetEntity="Member")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
*/
private $author;
/**
* Set author
*
* #param Member $author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Get author
*
* #return Member
*/
public function getAuthor()
{
return $this->author;
}
}
/**
* #ORM\Table(name="visitor_comments")
*/
class VisitorComment extends Comment
{
/**
* owning side
*
* #var Visitor $author
*
* #ORM\ManyToOne(targetEntity="Visitor")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
*/
private $author;
/**
* Set author
*
* #param string $author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Get author
*
* #return Visitor
*/
public function getAuthor()
{
return $this->author;
}
}
The exception occurs when I call $comment->getAuthor()->getFirstName() <assuming that author which is either a Member or Visitor entity has firstName property>. The getAuthor() in this case returns a proxy class of either VisitorProxy or MemberProxy.
Kindly help me. I'm still new to doctrine.
As Floricel found out, this can be caused by an invalid foreign key in a column that's points to the table that the Proxy class references.
#Dave Lancea is right I changed a FK to not Null and then started getting this error, manually updated a broken record, making it point to an existing entity and problem gone.

Generate merged entity class files with symfony2

I'm a little bit stuck with my poor knowledge of Symfony2 and Doctrine. Here is what I'm trying to do: I have two different files containing a class definition of the same class. I want to merge these two into a new class file.
I have an existing entity class file Foo.php:
/**
* #ORM\Entity
* #ORM\Table(name="foo")
*/
class Foo
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*
* #var int
*/
protected $id;
/**
* #ORM\Column(type="string")
*
* #var string
*/
protected $name;
/**
* #param string $name
* #return void
*/
public function setName($name)
{
$this->name = (string) $name;
}
/**
* #return string name
*/
public function getName()
{
return $this->name;
}
protected function someMagic($in) {
die('no magic happens.');
}
}
and a second entity class file with the same name Foo.php:
/**
* #ORM\Entity
* #ORM\Table(name="foo")
*/
class Foo
{
/**
* #ORM\Column(type="string")
*
* #var string
*/
protected $color;
/**
* #param string $name
* #return void
*/
public function setColor($color)
{
$this->color = $this->someColorMagic($color);
}
/**
* #return string name
*/
public function getColor()
{
return $this->color;
}
protected function someMagic($in) {
return 'magic: ' . $out;
}
}
How can I merge these two together (not at runtime, just during installation of a symfony application - could be done with a symfony console command like foobar:install) so I get a merged class Foo written to a file FooExtended.php that contains properties and methods of both classes and the doctrine annotations preserved?
Does Symfony (or the DoctrineBundle within) support stuff like this out of the box? Or can someone point me into the right direction how this can be achieved?
It now turned out with some changes in design I can solve my problem with simple class inheritance. So there is no need for a class merging at design time.