<?php

declare( strict_types=1 );

namespace DocketConnector\Common\Utilities;

use Stringy\Stringy as Stringy;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Abort if this file is called directly.
}

if ( ! class_exists( Strings::class ) ) {
	/**
	 * Make dealing with strings easier.
	 *
	 * Don't add new methods that duplicate functionality already possible via Stringy.
	 */
	class Strings {

		/**
		 * Wrapper for the Stringy library.
		 *
		 * Must cast result to `(string)` or use `->toString()` as the last chained method to get the actual string value.
		 * Example:
		 * $file_name = 'admin.css';
		 * $file_name = ( new Strings() )->stringy($file_name)->removeRight('.min.css' )->removeRight('.css')->toString();
		 * Result: 'admin'.
		 *
		 * @link https://github.com/voku/Stringy#oo-and-chaining How-to's and all available functions.
		 *
		 * @param mixed $stringy
		 *
		 * @return Stringy
		 */
		public function stringy( $stringy ) {
			return Stringy::create( $stringy );
		}

		/**
		 * Whether is a non-blank string.
		 *
		 * @param mixed $value
		 *
		 * @return bool
		 */
		public function is_non_blank_string( $value ): bool {
			return is_string( $value ) && '' !== trim( $value );
		}

		/**
		 * Whether is string of '1' or '0'.
		 *
		 * @since 1.1.0
		 *
		 * @param mixed $value
		 *
		 * @return bool
		 */
		public function is_1_or_0_string( $value ): bool {
			return '1' === $value || '0' === $value;
		}

	}
}
