original_string: protected function _checkDuplicate($name, $config)
      {
          /** @var \Cake\Core\InstanceConfigTrait $existing */
          $existing = $this->_loaded[$name];
          $msg = sprintf('The "%s" alias has already been loaded', $name);
          $hasConfig = method_exists($existing, 'config');
          if (!$hasConfig) {
              throw new RuntimeException($msg);
          }
          if (empty($config)) {
              return;
          }
          $existingConfig = $existing->getConfig();
          unset($config['enabled'], $existingConfig['enabled']);
  
          $fail = false;
          foreach ($config as $key => $value) {
              if (!array_key_exists($key, $existingConfig)) {
                  $fail = true;
                  break;
              }
              if (isset($existingConfig[$key]) && $existingConfig[$key] !== $value) {
                  $fail = true;
                  break;
              }
          }
          if ($fail) {
              $msg .= ' with the following config: ';
              $msg .= var_export($existingConfig, true);
              $msg .= ' which differs from ' . var_export($config, true);
              throw new RuntimeException($msg);
          }
      }
code: protected function _checkDuplicate($name, $config)
      {
          /** @var \Cake\Core\InstanceConfigTrait $existing */
          $existing = $this->_loaded[$name];
          $msg = sprintf('The "%s" alias has already been loaded', $name);
          $hasConfig = method_exists($existing, 'config');
          if (!$hasConfig) {
              throw new RuntimeException($msg);
          }
          if (empty($config)) {
              return;
          }
          $existingConfig = $existing->getConfig();
          unset($config['enabled'], $existingConfig['enabled']);
  
          $fail = false;
          foreach ($config as $key => $value) {
              if (!array_key_exists($key, $existingConfig)) {
                  $fail = true;
                  break;
              }
              if (isset($existingConfig[$key]) && $existingConfig[$key] !== $value) {
                  $fail = true;
                  break;
              }
          }
          if ($fail) {
              $msg .= ' with the following config: ';
              $msg .= var_export($existingConfig, true);
              $msg .= ' which differs from ' . var_export($config, true);
              throw new RuntimeException($msg);
          }
      }
code_tokens: protected function _checkDuplicate ( $ name , $ config ) { /** @var \Cake\Core\InstanceConfigTrait $existing */ $ existing = $ this -> _loaded [ $ name ] ; $ msg = sprintf ( 'The "%s" alias has already been loaded' , $ name ) ; $ hasConfig = method_exists ( $ existing , 'config' ) ; if ( ! $ hasConfig ) { throw new RuntimeException ( $ msg ) ; } if ( empty ( $ config ) ) { return ; } $ existingConfig = $ existing -> getConfig ( ) ; unset ( $ config [ 'enabled' ] , $ existingConfig [ 'enabled' ] ) ; $ fail = false ; foreach ( $ config as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ existingConfig ) ) { $ fail = true ; break ; } if ( isset ( $ existingConfig [ $ key ] ) && $ existingConfig [ $ key ] !== $ value ) { $ fail = true ; break ; } } if ( $ fail ) { $ msg .= ' with the following config: ' ; $ msg .= var_export ( $ existingConfig , true ) ; $ msg .= ' which differs from ' . var_export ( $ config , true ) ; throw new RuntimeException ( $ msg ) ; } }
docstring: Check for duplicate object loading.
  
  If a duplicate is being loaded and has different configuration, that is
  bad and an exception will be raised.
  
  An exception is raised, as replacing the object will not update any
  references other objects may have. Additionally, simply updating the runtime
  configuration is not a good option as we may be missing important constructor
  logic dependent on the configuration.
  
  @param string $name The name of the alias in the registry.
  @param array $config The config data for the new instance.
  @return void
  @throws \RuntimeException When a duplicate is found.
docstring_tokens: Check for duplicate object loading .