<commit_before><?php

namespace Nip\Filesystem;

use League\Flysystem\FilesystemInterface;

/**
 * Class File
 * @package Nip\Filesystem
 *
 * @method FilesystemInterface|FileDisk getFilesystem
 */
class File extends \League\Flysystem\File
{

    /**
     * @var
     */
    protected $name;

    /**
     * @var
     */
    protected $url;

    /**
     * @param string $name
     * @return $this
     */
    public function setFileName($name)
    {
        $path_parts = pathinfo($this->getPath());
        $path_parts['filename'] = $name;
        $this->setPath(
            $path_parts['dirname']
            . '/' . $path_parts['filename'] . '.' . $path_parts['extension']
        );

        return $this;
    }

    /**
     * Get File path with init check
     *
     * @return string
     */
    public function getPath()
    {
        if (!$this->path) {
            $this->initPath();
        }
        return parent::getPath();
    }

    /**
     * @return void
     */
    protected function initPath()
    {
        $this->setPath($this->getPathFolder() . $this->getName());
    }

    /**
     * @inheritdoc
     */
    public function setPath($path)
    {
        $name = pathinfo($path, PATHINFO_BASENAME);
        $this->setName($name);
        return parent::setPath($path);
    }

    /**
     * @return string
     */
    public function getPathFolder()
    {
        return '/';
    }

    /**
     * @return mixed
     */
    public function getName()
    {
        if (!$this->name) {
            $this->initName();
        }
        return $this->name;
    }

    /**
     * @param string $name
     * @return $this
     */<commit_msg>add name parsing for File in constructor from path<commit_after><?php

namespace Nip\Filesystem;

use League\Flysystem\FilesystemInterface;

/**
 * Class File
 * @package Nip\Filesystem
 *
 * @method FilesystemInterface|FileDisk getFilesystem
 */
class File extends \League\Flysystem\File
{

    /**
     * @var
     */
    protected $name;
    /**
     * @var
     */
    protected $url;

    /**
     * @inheritdoc
     */
    public function __construct(FilesystemInterface $filesystem = null, $path = null)
    {
        $this->parseNameFromPath($path);
        return parent::__construct($filesystem, $path);
    }

    /**
     * @param $path
     */
    protected function parseNameFromPath($path)
    {
        $name = pathinfo($path, PATHINFO_BASENAME);
        $this->setName($name);
    }

    /**
     * @param string $name
     * @return $this
     */
    public function setFileName($name)
    {
        $path_parts = pathinfo($this->getPath());
        $path_parts['filename'] = $name;
        $this->setPath(
            $path_parts['dirname']
            . '/' . $path_parts['filename'] . '.' . $path_parts['extension']
        );

        return $this;
    }

    /**
     * Get File path with init check
     *
     * @return string
     */
    public function getPath()
    {
        if (!$this->path) {
            $this->initPath();
        }
        return parent::getPath();
    }

    /**
     * @return void
     */
    protected function initPath()
    {
        $this->setPath($this->getPathFolder() . $this->getName());
    }

    /**
     * @inheritdoc
     */
    public function setPath($path)
    {
        $this->parseNameFromPath($path);
        return parent::setPath($path);
    }

    /**
     * @return string
     */
    public function getPathFolder()
    {
        return '/';
    }

    /**
     * @return mixed
     */
    public function getName()
    {
        if (!$this->name) {
            $this->initName();
        }
        return $this->name;
    }

    /**
     * @param string $name
     * @return $this
     */
{'fraction_non_alphanumeric': 0.15266970753957607, 'fraction_numerical': 0.0, 'mean_word_length': 1.717201166180758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '479731', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1125, 'n_words': 214}