Skip to content

Conversation

@NikitaYakovlev
Copy link
Contributor

@NikitaYakovlev NikitaYakovlev commented Jun 8, 2023

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@NikitaYakovlev NikitaYakovlev requested a review from DenTray June 8, 2023 14:12
@NikitaYakovlev NikitaYakovlev self-assigned this Jun 8, 2023
Comment on lines 375 to 387
if (is_string($rule)) {
return $rule;
}

$reflectionRule = new ReflectionClass($rule);

if ($reflectionRule->hasMethod('__toString')) {
return $rule->__toString();
}

$ruleName = preg_replace('/Rule$/', '', $reflectionRule->getShortName());

return $this->toSnakeCase($ruleName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (is_string($rule)) {
return $rule;
}
$reflectionRule = new ReflectionClass($rule);
if ($reflectionRule->hasMethod('__toString')) {
return $rule->__toString();
}
$ruleName = preg_replace('/Rule$/', '', $reflectionRule->getShortName());
return $this->toSnakeCase($ruleName);
if (is_object($rule)) {
if (method_exists($rule, '__toString')) {
return $rule->__toString();
}
$shortName = extract_last_part(get_class($class), '\\')
$ruleName = preg_replace('/Rule$/', '', $shortName);
return $this->toSnakeCase($ruleName);
}
return $rule;


public static function toSnakeCase(string $string): string
{
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $string));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $string));
return (function_exists('snake_case')) ? snake_case($string) : Str::snake($string);

Nikita Yakovlev and others added 5 commits June 13, 2023 18:04
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@DenTray DenTray merged commit 2c252d6 into master Jun 14, 2023
@DenTray DenTray deleted the 87_ability_to_work_with_rule_facade branch September 18, 2023 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants