<commit_before><?php

namespace Graviton\RestBundle\HttpFoundation;

/**
 * Represents a Link header item.
 *
 * Based on Symfony\Component\HttpFoundation\AcceptHeaderItem.
 *
 * @category GravitonRestBundle
 * @package  Graviton
 * @author   <NAME> <<EMAIL>>
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link     http://swisscom.com
 */
class LinkHeaderItem
{
    /**
     * @var string
     */
    private $uri;

    /**
     * @var array
     */
    private $attributes = array();

    /**
     * Constructor.
     *
     * @param string $uri        uri value of item
     * @param array  $attributes array of attributes
     *
     * @return \Graviton\RestBundle\HttpFoundation\LinkHeaderItem
     */
    public function __construct($uri, array $attributes = array())
    {
        $this->uri = $uri;

        foreach ($attributes as $name => $value) {
            $this->setAttribute($name, $value);
        }
    }

    /**
     * Builds a LinkHeaderItem instance from a string.
     *
     * @param string $itemValue value of a single link header
     *
     * @return \Graviton\RestBundle\HttpFoundation\LinkHeaderItem
     */
    public static function fromString($itemValue)
    {
        $bits = preg_split('/(".+?"|[^;]+)(?:;|$)/', $itemValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $value = array_shift($bits);
        $attributes = array();

        foreach ($bits as $bit) {
            list($bitName, $bitValue) = explode('=', trim($bit));

            $bitValue = self::trimEdge($bitValue, '"');
            $bitValue = self::trimEdge($bitValue, '\'');

            $attributes[$bitName] = $bitValue;
        }

        $url = self::trimEdge($value, '<');

        return new self($url, $attributes);
    }

    /**
     * cast item to string
     *
     * @return string
     */
    public function __toString()
    {
        $values = array('<'.$this->uri.'>');

        foreach ($this->attributes as $name => $value) {
            $values[] = sprintf('%s="%s"', $name, $value);
        }

        return implode('; ', $values);
    }

    /**
     * Get URI.
     *
     * @return string
     */
    public function getUri()
    {
        return $this->uri;
    }

    /**
     * Set a new URI.
     *
     * @param string $uri new URI value
     *
     * @return LinkHeaderItem
     */
    public function setUri($uri)
    {
        $this->uri = $uri;

        return $this;
    }

    /**
     * Get rel attribute
     *
     * @return string
     */
    public function getRel()
    {
        return empty($this->getAttribute('rel')) ? '' : $this->getAttribute('rel');
    }

    /**
     * Set attribute
     *
     * @param string $name  attribute name
     * @param string $value attribute value
     *
     * @return LinkHeaderItem
     */
    public function setAttribute($name, $value)
    {
        $this->attributes[$name] = $value;

        return $this;
    }

    /**
     * Get an attribute.
     *
     * @param string $name attribute name
     *
     * @return string
     */
    public function getAttribute($name)
    {
        return empty($this->attributes[$name]) ? '' : $this->attributes[$name];
    }

    /**
     * trim edge of string if char maches
     *
     * @param string $string string
     * @param string $char   char
     *
     * @return string
     */
    private static function trimEdge($string, $char)
    {
        if (substr($string, 0, 1) == $char) {
            $string = substr($string, 1, -1);
        }

        return $string;
    }
}
<commit_msg>Fixed: empty() does not support expressions prior to version 5.5 (did not know we are testing on 5.4 as well)<commit_after><?php

namespace Graviton\RestBundle\HttpFoundation;

/**
 * Represents a Link header item.
 *
 * Based on Symfony\Component\HttpFoundation\AcceptHeaderItem.
 *
 * @category GravitonRestBundle
 * @package  Graviton
 * @author   <NAME> <<EMAIL>>
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link     http://swisscom.com
 */
class LinkHeaderItem
{
    /**
     * @var string
     */
    private $uri;

    /**
     * @var array
     */
    private $attributes = array();

    /**
     * Constructor.
     *
     * @param string $uri        uri value of item
     * @param array  $attributes array of attributes
     *
     * @return \Graviton\RestBundle\HttpFoundation\LinkHeaderItem
     */
    public function __construct($uri, array $attributes = array())
    {
        $this->uri = $uri;

        foreach ($attributes as $name => $value) {
            $this->setAttribute($name, $value);
        }
    }

    /**
     * Builds a LinkHeaderItem instance from a string.
     *
     * @param string $itemValue value of a single link header
     *
     * @return \Graviton\RestBundle\HttpFoundation\LinkHeaderItem
     */
    public static function fromString($itemValue)
    {
        $bits = preg_split('/(".+?"|[^;]+)(?:;|$)/', $itemValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $value = array_shift($bits);
        $attributes = array();

        foreach ($bits as $bit) {
            list($bitName, $bitValue) = explode('=', trim($bit));

            $bitValue = self::trimEdge($bitValue, '"');
            $bitValue = self::trimEdge($bitValue, '\'');

            $attributes[$bitName] = $bitValue;
        }

        $url = self::trimEdge($value, '<');

        return new self($url, $attributes);
    }

    /**
     * cast item to string
     *
     * @return string
     */
    public function __toString()
    {
        $values = array('<'.$this->uri.'>');

        foreach ($this->attributes as $name => $value) {
            $values[] = sprintf('%s="%s"', $name, $value);
        }

        return implode('; ', $values);
    }

    /**
     * Get URI.
     *
     * @return string
     */
    public function getUri()
    {
        return $this->uri;
    }

    /**
     * Set a new URI.
     *
     * @param string $uri new URI value
     *
     * @return LinkHeaderItem
     */
    public function setUri($uri)
    {
        $this->uri = $uri;

        return $this;
    }

    /**
     * Get rel attribute
     *
     * @return string
     */
    public function getRel()
    {
        $relation = $this->getAttribute('rel');

        return empty($relation) ? '' : $relation;
    }

    /**
     * Set attribute
     *
     * @param string $name  attribute name
     * @param string $value attribute value
     *
     * @return LinkHeaderItem
     */
    public function setAttribute($name, $value)
    {
        $this->attributes[$name] = $value;

        return $this;
    }

    /**
     * Get an attribute.
     *
     * @param string $name attribute name
     *
     * @return string
     */
    public function getAttribute($name)
    {
        return empty($this->attributes[$name]) ? '' : $this->attributes[$name];
    }

    /**
     * trim edge of string if char maches
     *
     * @param string $string string
     * @param string $char   char
     *
     * @return string
     */
    private static function trimEdge($string, $char)
    {
        if (substr($string, 0, 1) == $char) {
            $string = substr($string, 1, -1);
        }

        return $string;
    }
}

{'fraction_non_alphanumeric': 0.14694945599779644, 'fraction_numerical': 0.0019281090758848643, 'mean_word_length': 1.9317723052079128, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3831604', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2169, 'n_words': 525}