Skip to content

masoudomidvar/string-truncator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Truncator

The purpose of this small application is to truncate a given string to a specified length with below conditions:
- The preview should never be longer than 1000 characters.
- When possible, the preview should end after a complete sentence.

It is implemented with Pure PHP.

Prerequisites

  • PHP 8.1 or higher
  • An available localhost

Project Information

I have implemented the single functionality of this app in a module called StringTruncator.

Some design patterns like Factory and Facade and Data Transfer Object are used inside this module.

Various OOP principles are used in this application.

StringTruncatorTransfer class is used as the DTO to handle data used inside StringTruncator module.

StringTruncatorFacade class has a truncateString method which is considered as the main API to this module.

StringTruncatorFactory class is used to instantiate the classes inside the StringTruncator module.

Test

StringTruncatorTest class is used to test this module.

A bunch of different test scenarios are defined in the examples method.

Each scenario consists of:

  • String: The original string to be truncated.
  • Limit: An integer to specify the length of truncation.
  • Expected: Expected string after truncation.
  • Points: Points recieved after truncation.

Run

  1. Clone the project in your localhost directory

    git clone https://github.com/masoudomidvar/string-truncator.git
  2. Open the string-truncator directory in your localhost. By doing this, the test will be executed.

    http://localhost/string-truncator

About

A small application made with Pure PHP to truncate different types of string.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages