class_groups as $name ) { $name_lc = $name . '_lc'; $this->$name_lc = array_map( 'strtolower', $this->$name ); $this->$name = array_combine( $this->$name_lc, $this->$name ); } } /** * Groups of classes to restrict. * * @since 3.0.0 * * @return array */ public function getGroups() { $groups = array(); foreach ( $this->class_groups as $name ) { $name_lc = $name . '_lc'; $groups[ $name ] = array( 'classes' => $this->$name_lc, ); } return $groups; } /** * Process a matched token. * * @since 3.0.0 * * @param int $stackPtr The position of the current token in the stack. * @param string $group_name The name of the group which was matched. Will * always be 'wp_classes'. * @param string $matched_content The token content (class name) which was matched. * in its original case. * * @return void */ public function process_matched_token( $stackPtr, $group_name, $matched_content ) { $matched_unqualified = ltrim( $matched_content, '\\' ); $matched_lowercase = strtolower( $matched_unqualified ); $matched_proper_case = $this->get_proper_case( $matched_lowercase ); if ( $matched_unqualified === $matched_proper_case ) { // Already using proper case, nothing to do. return; } $warning = 'It is strongly recommended to refer to classes by their properly cased name. Expected: %s Found: %s'; $data = array( $matched_proper_case, $matched_unqualified, ); $this->phpcsFile->addWarning( $warning, $stackPtr, 'Incorrect', $data ); } /** * Match a lowercase class name to its proper cased name. * * @since 3.0.0 * * @param string $matched_lc Lowercase class name. * * @return string */ private function get_proper_case( $matched_lc ) { foreach ( $this->class_groups as $name ) { $current = $this->$name; // Needed to prevent issues with PHP < 7.0. if ( isset( $current[ $matched_lc ] ) ) { return $current[ $matched_lc ]; } } // Shouldn't be possible. return ''; // @codeCoverageIgnore } }