PhpStorm Cookbook
By Ankur Kumar and Mukund Chaudhary
()
About this ebook
PhpStorm is a commercial, cross-platform IDE for PHP. It provides an intelligent editor for PHP, HTML, and JavaScript with on-the-fly code analysis and automated refactoring for PHP and JavaScript code.
In this book, you will learn about accessing project files, maximizing and reordering views, and editors. Going ahead, you will learn how to access elements, search code, compare files, and integrate frameworks. After gaining in-depth knowledge of testing and debugging, you will learn about PHP development, refactoring and building applications with ease of handling, and integrating frameworks. You will also test and debug them using PhpStorm and then learn how to use Phing and plugins. By the end of this book, you will have learned all about Phing and cooking plugins.
Related to PhpStorm Cookbook
Related ebooks
CakePHP 1.3 Application Development Cookbook Rating: 0 out of 5 stars0 ratingsPHP Ajax Cookbook Rating: 2 out of 5 stars2/5AngularJS Web Application Development Cookbook Rating: 0 out of 5 stars0 ratingsMeteor Cookbook Rating: 5 out of 5 stars5/5HTML5 Data and Services Cookbook Rating: 5 out of 5 stars5/5HTML5 Graphing and Data Visualization Cookbook Rating: 0 out of 5 stars0 ratingsAlfresco 3 Cookbook Rating: 0 out of 5 stars0 ratingsHTML5 Multimedia Development Cookbook Rating: 0 out of 5 stars0 ratingsiOS Development with Xamarin Cookbook Rating: 0 out of 5 stars0 ratingsASP.NET jQuery Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsLucene 4 Cookbook Rating: 0 out of 5 stars0 ratingsJavaFX 1.2 Application Development Cookbook Rating: 0 out of 5 stars0 ratingsJasmine Cookbook Rating: 5 out of 5 stars5/5AJAX Interview Questions, Answers, and Explanations: AJAX Certification Review Rating: 0 out of 5 stars0 ratingsjQuery Mobile Web Development Essentials - Third Edition Rating: 0 out of 5 stars0 ratingsPHP 5 CMS Framework Development - 2nd Edition Rating: 0 out of 5 stars0 ratingsMySQL 5.1 Plugin Development Rating: 0 out of 5 stars0 ratingsPHPEclipse: A User Guide Rating: 3 out of 5 stars3/5jQuery UI 1.7: The User Interface Library for jQuery Rating: 0 out of 5 stars0 ratingsMeteor Design Patterns Rating: 0 out of 5 stars0 ratingsEmber.js in Action Rating: 0 out of 5 stars0 ratingsFlex 3 with Java Rating: 0 out of 5 stars0 ratingsPHP for Beginners Rating: 0 out of 5 stars0 ratingsMulti-Tier Application Programming with PHP: Practical Guide for Architects and Programmers Rating: 0 out of 5 stars0 ratingsjQuery Hotshot Rating: 0 out of 5 stars0 ratingsjQuery 1.3 with PHP Rating: 0 out of 5 stars0 ratingsNW.js Essentials Rating: 0 out of 5 stars0 ratingsResponsive Design High Performance Rating: 0 out of 5 stars0 ratingsFlex on Java Rating: 0 out of 5 stars0 ratingsPHP Web 2.0 Mashup Projects: Practical PHP Mashups with Google Maps, Flickr, Amazon, YouTube, MSN Search, Yahoo! Rating: 0 out of 5 stars0 ratings
Enterprise Applications For You
Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Systems Thinking: Managing Chaos and Complexity: A Platform for Designing Business Architecture Rating: 4 out of 5 stars4/5The Ridiculously Simple Guide to Google Docs: A Practical Guide to Cloud-Based Word Processing Rating: 0 out of 5 stars0 ratingsScrivener For Dummies Rating: 4 out of 5 stars4/5Enterprise AI For Dummies Rating: 3 out of 5 stars3/5Bitcoin For Dummies Rating: 4 out of 5 stars4/5The New Email Revolution: Save Time, Make Money, and Write Emails People Actually Want to Read! Rating: 5 out of 5 stars5/5Create Income through Self-Publishing: An Author's Approach on Generating Wealth by Self-Publishing Rating: 5 out of 5 stars5/5Excel Formulas That Automate Tasks You No Longer Have Time For Rating: 5 out of 5 stars5/5QuickBooks 2024 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsChatGPT Ultimate User Guide - How to Make Money Online Faster and More Precise Using AI Technology Rating: 0 out of 5 stars0 ratingsExcel 2016 For Dummies Rating: 4 out of 5 stars4/5Excel 2019 For Dummies Rating: 3 out of 5 stars3/5QuickBooks 2023 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsEssential Office 365 Third Edition: The Illustrated Guide to Using Microsoft Office Rating: 3 out of 5 stars3/550 Useful Excel Functions: Excel Essentials, #3 Rating: 5 out of 5 stars5/5Change Management for Beginners: Understanding Change Processes and Actively Shaping Them Rating: 5 out of 5 stars5/5ConfigMgr - An Administrator's Guide to Deploying Applications using PowerShell Rating: 5 out of 5 stars5/5QuickBooks 2021 For Dummies Rating: 0 out of 5 stars0 ratingsLearn SQLite in 24 Hours Rating: 0 out of 5 stars0 ratingsNotion for Beginners: Notion for Work, Play, and Productivity Rating: 4 out of 5 stars4/5Excel Formulas and Functions 2020: Excel Academy, #1 Rating: 4 out of 5 stars4/5Microsoft Outlook 2016/2019/365 User Guide Rating: 5 out of 5 stars5/5Excel : The Complete Ultimate Comprehensive Step-By-Step Guide To Learn Excel Programming Rating: 0 out of 5 stars0 ratings
Reviews for PhpStorm Cookbook
0 ratings0 reviews
Book preview
PhpStorm Cookbook - Ankur Kumar
Table of Contents
PhpStorm Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Cooking with PhpStorm
Introduction
Showing/hiding views
How to do it...
How it works...
Customizing a view
How to do it...
How it works...
Accessing any project file
Getting ready
How to do it...
How it works…
Maximizing views and editors
How to do it...
Going back to the previous editor
Getting ready
How to do it...
There's more…
Going back to the previous edit location
Getting ready
How to do it...
Linking views to editors
How to do it...
Creating a key binding
How to do it...
How it works...
Creating a bookmark
How to do it...
Restoring deleted resources
Getting ready
How to do it...
How it works...
Customizing with PhpStorm
Getting ready
How to do it...
See also
Adding an include path
Getting ready
How to do it...
Excluding unwanted directories from the index
Getting ready
How to do it...
How it works…
Using code completion
Getting ready
How to do it...
How it works...
2. PHP Development
Introduction
Creating a PHP project using Composer
Getting ready
How to do it...
How it works...
Creating an empty project
Getting ready
How to do it...
How it works...
Reusing an existing project
Getting ready
How to do it...
Creating a new PHP class
Getting ready
How to do it...
How it works...
Creating a new PHP method
Getting ready
How to do it...
How it works...
Adding the getter/setter methods
Getting ready
How to do it...
How it works...
Creating delegate methods
Getting ready
How to do it...
How it works...
Surrounding code with control structures
Getting ready
How to do it...
How it works...
Finding the matching brace
Getting ready
How to do it...
How it works...
There's more...
Wrapping string
Commenting out a section of code and PHPDoc
Getting ready
How to do it...
How it works...
Creating a working set
Getting ready
How to do it...
Creating TODO tasks
Getting ready
How to do it...
How it works...
3. Refactoring and Building
Introduction
Renaming elements
How to do it...
Renaming a directory
Renaming a class
How it works...
There's more...
Renaming a method
Renaming member variables
See also...
Copying elements
How to do it...
How it works...
There's more...
Copying a class
Moving elements
How to do it...
Moving a directory
Moving a class
Moving a method
How to do it...
Moving a variable
How to do it...
Deleting elements
Getting ready
How to do it...
How it works…
Searching code in a project
Getting ready
How to do it...
How it works…
There's more...
Comparing files
Getting ready
How to do it...
How it works...
Restoring elements using comparison
Getting ready
How to do it...
How it works...
See also
Setting the run configuration
How to do it...
How it works...
There's more...
Running your code
Getting ready
How to do it...
How it works…
4. Integrating Framework
Introduction
Cooking with Symfony
Getting ready
How to do it...
How it works...
There's more...
Directory structure of Symfony
Creating a controller with Symfony
How to do it...
How it works...
Creating a model with Symfony
Getting ready
How to do it...
How it works...
Creating a view with Symfony
Getting ready
How to do it...
How it works...
Creating a model with the Yii framework
How to do it...
How it works...
Creating a controller with the Yii framework
How to do it...
How it works...
Creating a view with the Yii framework
How to do it...
How it works...
Creating a model with the Zend framework
How to do it...
How it works...
Creating a controller with the Zend framework
How it works...
Creating a view with the Zend framework
How to do it...
How it works...
There's more...
5. Testing and Debugging
Introduction
Installing PHPUnit
Getting ready
How to do it...
How it works...
Test case in PHPUnit
How to do it...
How it works...
Testing an application with PHPUnit
How to do it...
How it works...
Starting a debugging session
Getting ready
How to do it...
How it works...
Setting a breakpoint
How to do it...
How it works...
Configuring breakpoint conditions
How to do it...
How it works...
Creating exception breakpoints
How to do it...
How it works...
Stepping through your code
Getting ready
How to do it...
How it works...
Running to a line of code selected
How to do it...
How it works...
Watching expressions and variables
How to do it...
How it works...
Changing code on the fly
How to do it...
How it works...
Code coverage in PhpStorm
Getting ready
How to do it...
How it works...
There's more…
Purpose of code coverage
6. Using PhpStorm in a Team
Introduction
Getting a VCS server
Getting ready
How to do it...
How it works...
There's more...
Creating a VCS repository
Getting ready
How to do it...
How it works...
Connecting PhpStorm to a VCS repository
Getting ready
How to do it...
Storing a PhpStorm project in a VCS repository
Getting ready
How to do it...
How it works...
There's more...
Committing files to the VCS repository
Getting ready
How to do it...
How it works...
There's more...
Updating code from a VCS repository
Getting ready
How to do it...
How it works...
There's more...
Synchronizing your code with the VCS repository
Getting ready
How to do it...
How it works...
Examining the VCS repository
Getting ready
How to do it...
How it works...
Checking projects out of a VCS repository
Getting ready
How to do it...
How it works...
Creating code patches
Getting ready
How to do it...
How it works...
Creating VCS tags or branches
Getting ready
How to do it...
How it works...
There's more...
Creating a task for the team
Getting ready
How to do it...
How it works...
7. PhpStorm and Phing
Introduction
Connecting Phing and PhpStorm
How to do it...
How it works…
There's more…
Catching Phing build file syntax problems
Getting ready
How to do it…
How it works…
There's more…
Building a PhpStorm application using Phing
Getting ready
How to do it…
How it works…
Using a different build file
How to do it…
How it works…
Doing wonders with Phing
Getting ready
How to do it…
How it works…
There's more…
Using the Phing build view
How to do it…
How it works…
8. Cooking Library Plugins
Introduction
Creating a library plugin
Getting ready
How to do it…
How it works…
Refining the plugin
How to do it…
How it works…
Configuring the plugin with PhpStorm
How to do it…
There's more...
How it works…
Code hinting for the plugin
Getting ready
How to do it…
How it works…
9. Code Quality Analysis
Introduction
Mess detector and PhpStorm
Getting ready
How to do it…
How it works…
There's more...
Code sniffer and PhpStorm
Getting ready
How to do it…
How it works…
There's more...
Locating code duplicates
How to do it…
How it works…
There's more...
Code formatting and arrangement
How to do it…
How it works…
Index
PhpStorm Cookbook
PhpStorm Cookbook
Copyright © 2014 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2014
Production reference: 1221214
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78217-387-8
www.packtpub.com
Cover image by Gagandeep Sharma (<er.gagansharma@gmail.com>)
Credits
Authors
Mukund Chaudhary
Ankur Kumar
Reviewers
Shahin Katebi
Kirill Roskolii
Shuvankar Sarkar
Commissioning Editor
Ashwin Nair
Acquisition Editor
Kevin Colaco
Content Development Editor
Sharvari Tawde
Technical Editors
Manan Badani
Pankaj Kadam
Copy Editor
Sarang Chari
Project Coordinator
Judie Jose
Proofreaders
Maria Gould
Stephen Silk
Katherine Tarr
Indexer
Tejal Soni
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
About the Authors
If being knowledgeable and presentable is uniqueness, Mukund Chaudhary is the correct person to be termed unique. Having started his career primarily in programming, he developed an interest in management that led him to pursue an MBA even after obtaining an engineering degree.
Mukund is a team worker and is currently working as a technical product manager at Nityo Infotech Services Pvt. Ltd., New Delhi. His knowledge combined with the presentation skills give him an edge over his contemporaries. He likes to spend his spare time writing or with family. You can follow him on Twitter at https://twitter.com/mukund002.
I take this opportunity to extend my thanks to the strong and warm support provided to me by my family—my parents, my better half, and my grandfather. It was their motivation that led me to complete writing my first book ever.
My friends also deserve a fair share of the thanks. They were always there by my side to provide positive ideas and constructive criticism, as a result of which I was able to complete this tough task with much ease. I would also like to give a special thanks to the editors and all the people who played a part in the publishing of this book.
Ankur Kumar is an apt example of a dark horse. He often outperforms his contemporaries when he is in full flow. A team mentor by role, Ankur works for Nityo Infotech Services Pvt. Ltd. His seat remains vacant most of the time as he remains busy solving the problems of his teammates. Ankur has around 6 years of experience in the IT industry. He has worked in various roles for various companies across the globe. He has been working on LAMP stack for the last 3 years continually. He finds programming a challenge worth taking up and enjoys the one-to-one tussle with problem solving.
Ankur is a strong believer of the fact that a human should always make other humans happy in one way or the other. Even in the middle of tough tasks, he can be found cracking jokes (often on himself) to make the work environment lighter.
If someone is to be acknowledged, it should be the Almighty. It was due to his will that I got the opportunity to convert myself into a part-time author. Somewhere at the back of my mind, I always had this wish to impart the knowledge I gained all these years solving programming problems.
I sincerely thank everyone involved in the book-writing process to have understood the ideas that I wished to convey. The editors do deserve a fair share of thanks for their hard work.
My parents, my sister, and my better half are my real strength, and I will always be thankful to the Almighty for giving me a life worth living.
About the Reviewers
Shahin Katebi is a software architect and developer with 10 years of experience in creating apps for various platforms (Mac, iOS, Windows, and the Web). He works as a mobile solutions consultant with different companies in the business, marketing, and technical fields and also works with a few start-up teams worldwide. He teaches iOS/Mac OS development and as a mentor at Startup Weekend events, he helps start-up teams grow their own business. He is the founder and team leader at Seeb Co. (http://seeb.co/), a creative mobile app development organization that creates apps for customers around the world. He also runs and accelerates multiple start-up businesses in various fields worldwide.
Shahin has also helped with fact checking and technical editing for books such as iOS and OS X Network Programming Cookbook, Jon Hoffman, Packt Publishing.
I want to say a very special thanks to my beloved Nafiseh for her precious presence and support.
Kirill Roskolii is a passionate open source PHP/Drupal backend developer. He started his programming career as a freelance web developer in 2006. Afterwards, he created a small web studio with a couple of schoolmates and worked in ShvetsGroup, Kiev. Currently, he works as a lead Drupal backend developer in Trellon, LLC, maintaining CRM Core and a few other projects on Drupal.org.
I want to thank my wife for her support not only during the work on this book, but my entire life.
Shuvankar Sarkar is senior software engineer experienced in C#, .NET, PHP, and web development. He maintains his blog at http://shuvankar.com. Apart from official work, he is involved with several hobby projects (for example, http://tencovid.com). He is a member of Teamencoder (http://teamencoder.com). You can follow him on Twitter at @sonu041. Shuvankar is interested in computer security and Rubik's Cube.
I would like to thank my family for making my life easier and full of happiness.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
PhpStorm is a smart PHP IDE that gets your code and understands its structures. It provides code autocompletion, refactoring, syntax highlighting, and much more. PhpStorm makes debugging and testing really easy, especially with debugger configuration validation.
PhpStorm Cookbook contains several tutorials that will allow you to run PHP development at a good pace by helping you test and debug, which is often ignored by developers.
The book starts off focusing on how to cook using PhpStorm, gives you an overview of PHP development, and then dives deep into the details of refactoring and building your project using the PhpStorm IDE. After that, it moves to integrating frameworks and testing and debugging them. We then move on to using PhpStorm in a team, using Phing and cooking plugins. We conclude that this book will be of a great help to a PHP programmer who loves to use IDE and looks forward to working faster.
What this book covers
Chapter 1, Cooking with PhpStorm, gives you a quick overview about accessing a project, customizing a view, moving to the previous and next editor locations, and more.
Chapter 2, PHP Development, covers PHP classes; methods, including the getter/setter method; code blocks; commenting; and more.
Chapter 3, Refactoring and Building, includes renaming, copying, moving, and deleting elements; it includes code searching, comparing, and setting the run configuration.
Chapter 4, Integrating Framework, covers the need for a framework and how frameworks such as Symphony and Yii work with PhpStorm.
Chapter 5, Testing and Debugging, gives you an overview about installing PHPUnit, testing an application, setting a breakpoint, changing code on the fly, and much more.
Chapter 6, Using PhpStorm in a Team, includes creating a CVS repository, connecting PhpStorm to a CVS repository, committing a file, checking out projects, and much more.
Chapter 7, PhpStorm and Phing, gives you an overview of connecting Phing to PhpStorm, building an application, setting the Phing editor option, and more.
Chapter 8, Cooking Library Plugins, is about validating a plugin, code hinting for the plugin, and more.
Chapter 9, Code Quality Analysis, covers the mess detector and the code sniffer; it also covers locating code duplicates and code formatting and rearrangement.
What you need for this book
This book assumes you have prior knowledge of PHP and you have a computer with Apache, PHP, and PhpStorm IDE installed.
Who this book is for
This book is for all levels of web application developers who look forward to working faster and efficiently using PhpStorm IDE. It assumes that readers have prior knowledge of PHP development using the LAMP/WAMP environment; however, this book focusses on LAMP.
Sections
This book contains the following sections:
Getting ready
This section tells us what to expect in the recipe and describes how to set up any software or any preliminary settings needed for the recipe.
How to do it…
This section characterizes the steps to be followed to cook
the recipe.
How it works…
This section usually consists of a brief and detailed explanation of what happened in the previous section.
There's more…
It consists of additional information about the recipe in order to make the reader more anxious about the recipe.
See also
This section may contain references to the recipes.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: If a folder is provided in include path, it will be helpful in auto completion for include(), require(), and so on.
A block of code is set as follows:
class Dish {
/**
* @param string $dishName The name of the dish
*/
protected function addSalt(){ }
}
A command-line input or output is shown as:
svnadmin create /path/to/your/repo/
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: To turn this feature on, you need to select the checkbox adjacent to Sort lookup items lexicographically.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>, and