Skip to content

method.visibility

Ensure that methods visibility is set

Examples

  • Examples of correct code for this rule using default options

Class methods with visibility modifiers

php
<?php
class Database {
	public function getDatabaseStatus(){
		echo "connected to database";
	}
	
	public function setDatabaseStatus($status){
		echo "Status is set";
	}
	
	private function getMaxConnections(){
		echo "Max connections is 10";
	}
	
	private function setMaxConnections($connections){
		echo "Max connections is set";
	}
}
  • Examples of incorrect code for this rule using default options

Class methods without visibility modifiers

php
<?php
class Database {
	function getDatabaseStatus(){
		echo "connected to database";
	}
	
	function setDatabaseStatus($status){
		echo "Status is set";
	}
	
	function getMaxConnections(){
		echo "Max connections is 10";
	}
	
	function setMaxConnections($connections){
		echo "Max connections is set";
	}
}

Released under the MIT License.