Managing Copyright Notices in PhpStorm
Code repositories often have copyright notices in multiple places, and in some cases every file may have a copyright notice you want to update. PhpStorm now includes the Update Copyright… tool, which allows you to manage the copyright notices in single or multiple files across your project.
In order for PhpStorm to modify the copyright notices in your files, we first need to tell PhpStorm how to handle copyright in your project. The setting for copyright contains two parts, firstly a Copyright Profile, and secondly the scope.
Copyright Profiles define what the copyright notice in your files should look like. You can define (or manage) a copyright profile by using the
Copyright Profiles pane under
Editor -> Copyright in the settings dialog. The profile contains a template which contains how the copyright notice should look (in a Velocity template), and any rules that need to be defined on when and how to update notices.
A scope is simply the area of the project that you wish to effect, such as a single file, directory, or the entire project.
Once you’ve defined your profile and scope, you can assign a scope to a profile in the root
Copyright settings panel under the
Editor option in the settings dialog.
Lets take a look at how we can update the copyright notice in every file in the entire Zend\EventManager component.
Note: This component was chosen only because it has copyright notices in every file, and therefore is a good example to demonstrate the Copyright Tool.
After opening a new clone of Zend\EventManager in PhpStorm, we can open the Copyright Profile settings pane, and then click the
+ to create a new profile. Let’s call the new profile
PhpStorm has created a sample copyright text for us, which contains the velocity variable
$today.year that will automatically insert the current year. Once we update this so that it looks like the current standard Zend copyright notice, we can click
Apply (as we don’t need to modify the default detection or replacement rules).
By default, PhpStorm formats the copyright notice as a PHP comment block at the top of each file. If you wish to change the formatting, to add more spacing for example, you can do so from the
Formatting and then
PHP link in the left hand setting pane. Here, you can change the type of comment (from a comment block, to inline for example), add borders, and more.
Now we need to link this profile to a scope. From the
Copyright settings pane, simply click the
+ icon. In this instance the files we want to modify are in the
src directory, so from the dropdown in the Scope column, let’s select
Project Files. As we only have one profile created, PhpStorm automatically selects the
Zend profile for us.
Now we can use the
Update Copyright... under the code menu to run the Update Copyright tool. Before we run the tool, the copyright notice in Zend\EventManager is showing 2015.
If we run the Update Copyright tool against the assigned scope, we can see that the copyright year in every file has been updated and is now showing 2016.
– Gary and the PhpStorm Team
The Drive to Develop