Book Image

PhpStorm Cookbook

By : Mukund Chaudhary
Book Image

PhpStorm Cookbook

By: Mukund Chaudhary

Overview of this book

Table of Contents (16 chapters)
PhpStorm Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding the getter/setter methods


Adding getter and setter methods in PhpStorm is equally easy. All you need to do is have a member variable of the class. In the PizzaDish example, it was dishName.

Getting ready

To create getters and setters for dishName, PhpStorm provides that if you need to. Access the right-click context menu for the target variable, click on Generate and select Getters and Setters from the pop up. PhpStorm will create the desired getters and setters for the selected member.

Your PizzaDish class will now look like the following piece of code:

<?php
require_once 'Dish.php';

class PizzaDish extends Dish{
  private $dishName;
  
  /**
  * @param mixed $dishName
  */
  public function setDishName($dishName)
  {
    $this->dishName = $dishName;
  }
  
  /**
    * @return mixed
  */
  public function getDishName()
  {
    return $this->dishName;
  }
  function add($ingredientName){
    $this->setDishName($ingredientName);
    parent::add($this->dishName);
  }
}

How...