alex-5zi/hexlet-psr-linter

View on GitHub
src/Linter/LinterUtils.php

Summary

Maintainability
A
25 mins
Test Coverage
<?php

namespace hexletPsrLinter\Linter;

function isCamelCase($string, $upper = false, $twoCaps = false)
{
    if ($upper) {
        $legalChars = '^[A-Z][a-zA-Z0-9]{0,}$';
    } else {
        $legalChars = '^[a-z][a-zA-Z0-9]{0,}$';
    }

    if (preg_match("/$legalChars/", $string) === 0) {
        return false;
    }
    if (!$twoCaps) {
        $twoCapsPattern = '[A-Z]{2,}';
        if (preg_match("/$twoCapsPattern/", $string) > 0) {
            return false;
        }
    }
    return true;
}

function isUnderScore($string)
{
    $legalChars = '^[a-z][a-z0-9_]{0,}$';
    if (preg_match("/$legalChars/", $string) === 0) {
        return false;
    }

    $legalChars = '[a-z0-9]$';
    if (preg_match("/$legalChars/", $string) === 0) {
        return false;
    }

    $twoScore = '[_]{2,}';
    if (preg_match("/$twoScore/", $string) > 0) {
        return false;
    }

    return true;
}