Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4437: Allow child environment detectors to override false #4466

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Robo/Common/EnvironmentDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public static function isPantheonProdEnv() {
*/
public static function isLocalEnv() {
$results = self::getSubclassResults(__FUNCTION__);
if ($results) {
return TRUE;
if ( !empty($results) ) {
return !in_array(FALSE, $results);
}

return parent::isLocalEnv() && !self::isPantheonEnv() && !self::isCiEnv();
Expand All @@ -116,8 +116,8 @@ public static function isLocalEnv() {
*/
public static function isDevEnv() {
$results = self::getSubclassResults(__FUNCTION__);
if ($results) {
return TRUE;
if ( !empty($results) ) {
return !in_array(FALSE, $results);
}

return self::isAhDevEnv() || self::isPantheonDevEnv();
Expand All @@ -128,8 +128,8 @@ public static function isDevEnv() {
*/
public static function isStageEnv() {
$results = self::getSubclassResults(__FUNCTION__);
if ($results) {
return TRUE;
if ( !empty($results) ) {
return !in_array(FALSE, $results);
}

return self::isAhStageEnv() || self::isPantheonStageEnv();
Expand All @@ -140,8 +140,8 @@ public static function isStageEnv() {
*/
public static function isProdEnv() {
$results = self::getSubclassResults(__FUNCTION__);
if ($results) {
return TRUE;
if ( !empty($results) ) {
return in_array(TRUE, $results);
}

return self::isAhProdEnv() || self::isPantheonProdEnv();
Expand Down Expand Up @@ -339,7 +339,7 @@ private static function getSubclassResults($functionName) {
$results[] = call_user_func([$detector, $functionName]);
}
}
return array_filter($results);
return $results;
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc block for this function needs to be updated to account for false results being returned.

This significantly changes the behavior of multiple detectors being called, doesn't it? Previously, if any detector returned true that detector would 'win', i.e. the parent method would return true. Now, the result is going to vary by method. For instance, what should happen if one detector returns false and another returns true for isStageEnv or isProdEnv? I think this behavior needs to be consistent, and it needs to be documented.

Copy link
Author

@reubenmoes reubenmoes Feb 28, 2022

Choose a reason for hiding this comment

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

oh i have some inconsistency here. I had a change of approach last minute. Which one would be preferred?


option 1:

should happen if one detector returns false and another returns true for isStageEnv or isProdEnv
This would result in it being overall false.
If there is only one environment detector returning true - would be true
If there is only one environment detector returning false - would be false (and would not continue to call the parent method)

    if ( !empty($results) ) {
      return !in_array(FALSE, $results);
    }

Option 2: (seems like this would be more consistent with what was previously in place)

should happen if one detector returns false and another returns true for isStageEnv or isProdEnv
This would result in it being overall true.
If there is only one environment detector returning true - would be true
If there is only one environment detector returning false - would be false (and would not continue to call the parent method)

    if ( !empty($results) ) {
      return in_array(TRUE, $results);
    }

}

}