Для получения полного доступа
зарегистрируйтесь.
Snippet,  PHP

Get number of significant lines in the code


The code determines number of significant lines in the code. It skips newlines and comments. The plan is to skip doc-comments as well.

Can you improve it? Make it simpler and faster? Send your revisions. I think mine is the simplest one.

public function valid_length($code) {
	$count = 0;
	foreach (explode("\n", $code) as $line) {
		$line = trim($line);
		$line !== '' &&
		$line !== '{' &&
		$line !== '}' &&
		preg_match_all('~(?://|[#])~', $line) !== 1 ? $count ++ : false;
	}

	if ($count > 18) {
		$this->form_validation->set_message('valid_length', 'Your stash has more than 18 lines');

		return false;
	} else {
		return true;
	}
}
  logic algorithm parser

Автор


dfatt
  • Reputation: 260
  • Snippets : 53
  • Revisions : 7
Подписаться

Чтобы увидеть комментарии, нужно быть участником сообщества

Регистрация