original_string: public function replaceExtension($extension)
      {
          $atoms = $this->nameAtoms();
          if (array('', '') === $atoms) {
              if (null === $extension) {
                  return $this;
              }
  
              return $this->replaceName(
                  static::EXTENSION_SEPARATOR . $extension
              );
          }
  
          $numAtoms = count($atoms);
  
          if ($numAtoms > 1) {
              if (null === $extension) {
                  $replacement = array();
              } else {
                  $replacement = array($extension);
              }
  
              array_splice($atoms, -1, $numAtoms, $replacement);
          } elseif (null !== $extension) {
              $atoms[] = $extension;
          }
  
          return $this->replaceName(implode(self::EXTENSION_SEPARATOR, $atoms));
      }
code: public function replaceExtension($extension)
      {
          $atoms = $this->nameAtoms();
          if (array('', '') === $atoms) {
              if (null === $extension) {
                  return $this;
              }
  
              return $this->replaceName(
                  static::EXTENSION_SEPARATOR . $extension
              );
          }
  
          $numAtoms = count($atoms);
  
          if ($numAtoms > 1) {
              if (null === $extension) {
                  $replacement = array();
              } else {
                  $replacement = array($extension);
              }
  
              array_splice($atoms, -1, $numAtoms, $replacement);
          } elseif (null !== $extension) {
              $atoms[] = $extension;
          }
  
          return $this->replaceName(implode(self::EXTENSION_SEPARATOR, $atoms));
      }
code_tokens: public function replaceExtension ( $ extension ) { $ atoms = $ this -> nameAtoms ( ) ; if ( array ( '' , '' ) === $ atoms ) { if ( null === $ extension ) { return $ this ; } return $ this -> replaceName ( static :: EXTENSION_SEPARATOR . $ extension ) ; } $ numAtoms = count ( $ atoms ) ; if ( $ numAtoms > 1 ) { if ( null === $ extension ) { $ replacement = array ( ) ; } else { $ replacement = array ( $ extension ) ; } array_splice ( $ atoms , - 1 , $ numAtoms , $ replacement ) ; } elseif ( null !== $ extension ) { $ atoms [ ] = $ extension ; } return $ this -> replaceName ( implode ( self :: EXTENSION_SEPARATOR , $ atoms ) ) ; }
docstring: Replace this path's last extension.
  
  @param string|null $extension The replacement string, or null to remove the last extension.
  
  @return PathInterface A new path instance with the supplied extension replacing the existing one.
docstring_tokens: Replace this path s last extension .