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 `Zend`.
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
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…