• v5.0
    • Versions
    • master

 

  • Install Akeneo PIM
    • Install Akeneo PIM for development with Docker
    • Install Akeneo PIM manually
      • System Requirements
      • System installation on Debian 10 (Buster)
      • System installation on Ubuntu 18.04 (Bionic Beaver)
      • System installation on Ubuntu 20.04 (Focal Fossa)
      • Installing Akeneo PIM Community Edition (CE)
      • Installing Akeneo PIM Enterprise Edition (EE) with the Archive
      • Setting up the job queue daemon
      • Setting up the Events API
    • How to customize the Dataset
    • How to Add Translation Packs
  • Upgrade Akeneo PIM projects
    • How to apply a patch?
      • How to apply a patch - Community Edition
      • How to apply a patch - Enterprise Edition - Flexibility Cloud offer
      • How to apply a patch - Enterprise Edition - On Premise offer
    • Where is the Changelog?
    • How to upgrade to a minor version?
    • How to upgrade to a major version?
      • Upgrade from 3.2 to 4.0
      • Upgrade from 4.0 to 5.0
  • Import and Export data
    • How import works
    • Understanding the Product Import
    • Understanding the Product Export
    • Formats
      • Localized labels
      • Scopable labels
      • Association types data structure
      • Attribute data structure
      • Category data structure
      • Family data structure
      • Family variant data structure
      • Group data structure
      • Options data structure
      • Product data structure
      • Product model data structure
    • Akeneo Connectors
    • How to Customize Import / Export
      • How to create a new Connector
      • How to import Products from a XML file
      • How to clean a CSV file during a Product import
      • How to automate imports/exports
  • Manipulate the Akeneo PIM data
    • How to Customize Mass Edit Operations
      • How to register a new bulk action
      • How to Register a New Mass Edit Action on Products
    • How to Manipulate Products
      • How to Query Products
      • How to Create Products
      • How to Update Products
      • How to Validate Products
      • How to Save Products
      • How to Remove Products
    • How to Manipulate Non-Product Objects
      • How to Query Non-Product Objects
      • How to Create Non-Product Objects
      • How to Update Non-Product Objects
      • How to Validate Non-Product Objects
      • How to Save Non-Product Objects
      • How to Remove Non-Product Objects
    • How to add a custom action rule
      • General information about rule format
      • How to add a custom action in the rule engine
    • How to Define Access Control List
    • How to Customize the Catalog Structure
      • How to Create a Reference Data
    • How To Customize Teamwork Assistant (Enterprise Edition)
      • Customize notifications
      • Add a calculation step
      • How to log calculation step
      • Remove projects impacted by a custom catalog update
    • How to store assets externally
    • How to Configure Measurement Limits
  • Maintain Akeneo PIM projects
    • First aid kit
    • Bug qualification
    • Common issues
    • Scalability Guide
      • Audit with 3 Representative Catalogs
      • More than 10k attributes?
      • More than 10k families?
      • More than 10k categories?
      • More than 500 attributes usable in the product grids?
      • More than 100k products to export?
      • More than 1GB of product media to export?
    • How to purge history
      • How to Purge jobs executions
      • How to adapt the version purger to your needs
  • Contribute to Akeneo PIM
    • How to report an issue?
    • How to translate the user interface?
    • How to enhance the documentation?
    • How to contribute to a Connector?
    • How to submit a patch to the PIM?
    • How to contribute to the frontend part of the application
    • How behavior tests are architectured in the PIM?
      • Establishing Decorator Pattern
      • Using Spin In Behat
  • Use SSO authentication locally
  • Reference Entities
    • Configure Entity Limits
    • Create a new Reference Entity Attribute type
    • Enrich Records with a new Reference Entity Attribute type
    • Add a Custom Property to Your Custom Attribute Type
    • Refresh records completeness
  • Troubleshooting guide
  • Technical overview
    • Product Information
    • Teamwork Assistant (Enterprise Edition)
      • Project creation
      • Project completeness
      • Project Completeness widget
      • Catalog update impact
      • Scalability guide
      • Users permission summary for Behat tests
    • Collaborative workflow
      • Simple workflow
      • Partial workflow
  • Technical architecture
    • Best Practices
      • Create a project
      • Create a reusable bundle
      • Code Conventions
      • Coding Standards
    • How to implement your business logic using the event system
    • Events
      • Storage events
      • Workflow events (Enterprise Edition only)
    • How to Localize your data
      • How to change the PIM locale
      • How to Use Localizers
      • How to use Presenters
    • How to Add a Notification
    • Performances Guide
      • Memory usage of rules execution (Enterprise Edition)
      • Memory leak fix in Rules Engine (ORM)
      • More than 100 WYSIWYG editors in a page
      • PHP7 and HHVM Compatibility?
      • Job product batch size
    • How to Use the Web REST API
    • Standard format
      • Products
      • Other entities
      • Usage
    • Application Technical Information
      • Application Technical Dependencies
      • Server side set up for hosting
      • System Requirements
      • Recommended configuration
      • Client side configuration and compatibilities
      • Operation processes
      • Flow Matrix
  • Akeneo Cloud Edition
    • Flexibility
      • Environment accesses
      • System Administration & Services Management
      • Periodic tasks & Crontab configuration
      • Composer settings
      • Queue Management & Workers
      • Disk Usage Management
    • Serenity
  • Akeneo Onboarder
    • Prerequisites
    • How to install the Onboarder bundle
    • Synchronization
    • How to update a minor version or to apply a patch
      • How to update the Onboarder bundle - Enterprise Edition - Flexibility Cloud offer
      • How to update the Onboarder bundle - Enterprise Edition - On Premise offer
    • How to upgrade to a major version
    • Troubleshooting
    • How to uninstall the Onboarder bundle
    • Environment variables
      • Using the DotEnv file
      • Using environment variables

Coding Standards¶

When contributing code to Akeneo PIM, you must follow its coding standards (very close to Symfony Coding Standards).

Akeneo follows the standards defined in the PSR-0, PSR-1 and PSR-2 documents.

We use few extra rules defined in our configuration of php-cs-fixer https://github.com/akeneo/pim-community-dev/blob/5.0/.php_cs.php.

Example¶

Here is a short example containing most features described below:

<?php

namespace Acme;

/*
 * @author    FirstName LastName <email@domain.com>
 * @copyright 2015 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class FooBar
{
    const SOME_CONST = 42;

    protected $fooBar;

    /**
     * @param string $dummy Some argument description
     */
    public function __construct($dummy)
    {
        $this->fooBar = $this->transformText($dummy);
    }

    /**
     * @param string $dummy Some argument description
     * @param array  $options
     *
     * @throws \RuntimeException
     *
     * @return string|null Transformed input
     *
     * @deprecated Will be removed in x.y
     */
    protected function transformText($dummy, array $options = [])
    {
        $mergedOptions = array_merge(
            [
                'some_default'    => 'values',
                'another_default' => 'more values',
            ],
            $options
        );

        if (true === $dummy) {
            return;
        }

        if ('string' === $dummy) {
            if ('values' === $mergedOptions['some_default']) {
                return substr($dummy, 0, 5);
            }

            return ucwords($dummy);
        }

        throw new \RuntimeException(sprintf('Unrecognized dummy option "%s"', $dummy));
    }
}

Structure¶

  • Add a single space after each comma delimiter;

  • Add a single space around operators (==, &&, …);

  • Put immutable entities on the left of comparison statements (null === $var, 'string' === $this->test())

  • Add a comma after each array item in a multi-line array, even after the last one;

  • Add a blank line before return statements, unless the return is alone inside a statement-group (like an if statement);

  • Use braces to indicate control structure body regardless of the number of statements it contains;

  • Define one class per file - this does not apply to protected helper classes that are not intended to be instantiated from the outside and thus are not concerned by the PSR-0 standard;

  • Declare class properties before methods;

  • Declare public methods first, then protected ones;

  • Use parentheses when instantiating classes regardless of the number of arguments the constructor has;

  • Exception message strings should be concatenated using sprintf.

  • If we expect something from a method/function (i.e. the returned value of the method/function used by the caller) we should always do an explicit return (not return;).

Naming Conventions¶

  • Use camelCase, not underscores, for variable, function and method names, arguments;

  • Use underscores for option names and parameter names;

  • Use namespaces for all classes;

  • Prefix abstract classes with Abstract.

  • Suffix interfaces with Interface;

  • Suffix exceptions with Exception;

  • Use alphanumeric characters and underscores for file names;

  • Don’t forget to look at the more verbose Code Conventions document for more subjective naming considerations.

  • The use of Manager or Helper in a class is strictly forbidden because they quickly tend to contain a lot of not related methods

Visibility¶

Protected by default and public when necessary.

Usage of private is forbidden in the Core Components and Bundles.

We understand the advantages and know the drawbacks, we strictly follow this rule for now.

We still have a lot of discussions related to this point regarding the Open/Close principle.

An interesting resource on this topic private vs protected

Documentation¶

  • Add PHPDoc blocks for all classes, methods, and functions;

  • Omit the @return tag if the method does not return anything;

  • If your function returns an array of entity, use

    /**
     * @return string[]
     */
    
    /**
     * @return MyClass[]
     */
    
  • If your function returns an ArrayCollection of entity, use

    /**
     * @return ArrayCollection of string
     */
    
    /**
     * @return ArrayCollection of MyClass
     */
    
  • The @package and @subpackage annotations are not used.

  • Write a use statement if the PHPdoc needs it, instead of writing the FQCN.

License¶

  • Akeneo PIM is released under the OSL license, and the license reference has to be present at the top of every PHP file, in the class PHPDoc.

  • Some bundles, such as BatchBundle, are released under the MIT license, for these ones, please follow the repository convention.


Found a typo or a hole in the documentation and feel like contributing?
Join us on Github!