Skip to content

Instantly share code, notes, and snippets.

@alvin0319
Created January 12, 2021 03:15
Show Gist options
  • Save alvin0319/6611d0f363b5e42b3dc4f20c5160897b to your computer and use it in GitHub Desktop.
Save alvin0319/6611d0f363b5e42b3dc4f20c5160897b to your computer and use it in GitHub Desktop.
Introduce my coding style

It is mainly PSR-2 with a few exceptions.

  • Opening braces MUST go on the same line, and MUST NOT have spaces before.
  • else if MUST be written as elseif. (It is in PSR-2, but using a SHOULD)
  • Control structure keywords or opening braces MUST NOT have one space before or after them.
  • Code MUST use tabs for indenting.
  • Long arrays MAY be split across multiple lines, where each subsequent line is indented once.
  • Files MUST use only the <?php tag.
  • Files MUST NOT have an ending ?> tag.
  • Code MUST use namespaces.
  • Strings SHOULD use the double quote " except when the single quote is required.
  • All code SHOULD have parameter and type declarations where possible.
  • Strict types SHOULD be enabled on new files where it is sensible to do so.
  • All constant declarations SHOULD be preceded by a visibility modifier.
  • Declare return type if the return type is clear.
<?php

declare(strict_types=1);

namespace alvin0319\TestCase;

class TestCase{
	/** @var array */
	private $config = [];
	/** @var \mysqli */
	protected $mysqli;
	
	public function __construct(array $args, \mysqli $mysql){
		$this->config = $args;
		$this->mysqli = $mysqli;
	}
	
	public function getArgs() : array{
		return $this->args;
	}
	
	public function getMysqli() : \mysqli{
		return $this->mysqli;
	}
	
	public function setArgs(array $args) : void{
		$this->config = $args;
	}
}

Reference: PMMP Contributing.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment